Course(s) Evaluation

In this blog post I will include my thoughts about the classes TC3045 (Software Quality and Testing) and CB00881 (Smart Citizens)

First of all, these were my first and last classes (because I’m graduating and I’m not planning to do a Masters) using the Flipped Learning method. I found it very interesting because I had a lot of flexibility in terms of homeworks and tasks, at the start of the semester I was working in a full-time job so I have the option to complete all my pending assignments in my free time. To be honest, I should have been more careful about the deadlines and deliveries because I have a considerable amount of accumulated tasks to do at the end of the semester.

About the content of the classes and assignments, they met my expectations, there were some assignments that challenged myself and taught me new things. At the start of the semester, we have to write blogs weekly for CB00881, I wrote a few on time because I don’t have the writing habit developed, I don’t really like writing so much, but I want to. Recently I started to read more blogs about the new technologies, the updates and improvements in the actual ones, and some tutorial blogs to develop something using a language or framework. I want to share some knowledge to the world and start writing some blog stuff and link the code I used to my GitHub repo, I proposed myself that I want to contribute to some Open Source repos in order to thanks all the amazing people that are doing it and all the times I used those repos. I hope I will do it.

Ken is amazing teacher, he really knows how to transmit his knowledge and encourage you to learn. But apart of being a good teacher, he is a great human being, he is always open to talk to you about your thoughts, life, work, feelings and whatever you want, he will listen and he will be there to help.

DevOps Part II

We are on our first step to become a DevOps expert. We will begin setting up a Linux Server (NodeJS) on a Virtual Machine. I recommend VirtualBox, it is open source and very easy to set up.

Preparing VirtualBox for running Ubuntu

Launch VirtualBox and select “New”, the next prompt will appear. Make sure you select Linux and Ubuntu (32|64-bit) version.

Set the RAM

Select the Hard Drive Type

Your VM is almost ready, when you boot it from the first time, it prompts you to select the bootable file, make sure you select the *.iso file you downloaded from the Ubuntu webpage.

Follow the instructions prompted by the OS like creating an Username and Password, when it finished, we’re going to install the required packages for running Node.

Installing NodeJS & Git

First we need the curl package, open the Terminal app and type

sudo apt-get install curl

Next step is to download Node source, type the following command

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

Once finished, let’s install NodeJS by running the next command

sudo apt-get install -y nodejs

Finally, verify that node and npm are correctly installed by checking the version of each one

node -v
npm -v

Our next step is to install git, so we run the next command

sudo apt-get install git

And like node and npm, let’s verify the installation by checking the version

git --version

Now let’s create a repository for serving a simple webpage using node and express. In a new folder run npm init, and fill the prompted options. This will let us install node packages using npm. Install express by running npm install express. Let’s write some HTML and JavaScript.

index.html
index.js

In the package.json file, add a new script for running our development server.

"scripts": {    
"start": "node src/index.js"
}

Run the script typing npm run start and open the browser in http://localhost:8080, you should see the following

It works!

Remember to add git to the project.

Now, we’re going to write a small cron job in our Virtual Machine, type the following

crontab -e

Select your desired terminal editor and you’ll be able to edit or add cron jobs

At the end of the file we will write the cronjob, add something simple like this

* * * * * echo 'Hello Cron!' > $HOME/cron.txt

This task will be running every minute and overwrite the file with ‘Hello Cron!’, close the file and save it. Next go to your home directory in one minute and see that the file is created

Amazing! We wrote our first cronjob in Linux. This is the part II of a series of five posts

TCR && TDD

Testing the code is a fundamental part while developing an application, it ensures maintainability, usability and scalability. There are several test tools and frameworks for every ecosystem and programming language that makes the stage of deploying easier.

The method of “test && commit || revert” described by Kent Beck, called my attention, because it enforces the developer to write good tests because if a tests fails it returns the code to the last green commit (all passing tests), that’s why it has to check the code meticulously to ensure it won’t fail and also to save the last state of the code where it worked perfectly. Basically the command runs the nexts operations.

git commit -ma "Test worked" // if passed
git reset --hard // if not

In the experience I had testing my applications it always has been present the part that I do the commit, and then the tests fails in an specific case, so I go back and fix it, and then commit again but because of that fix another part crashed, and so on and so on, so definitely I will try this technique for making me more productive.

An area that is very important for me in the team is the DevOps, it’s impressive how you can speed the development and deployment of a project when you have a well structured CI/CD. I have a little experience in the DevOps area, setting up the CI/CD scripts and the pipelines for the VCS. It is very delightful seeing the tests passing in a deployment process, making newest versions of the application more maintainable and ready-to-deploy. DevOps is an area that every software company has to have.

Resultado de imagen para deployment software memes

https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864

hhttps://hanselminutes.com/663/test-commit-revert-with-kent-beck

Unit Testing in Node

Writing unit tests in Node is very easy, we are going to use 2 tools for doing that: Mocha and Chai.

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun

https://mochajs.org/

Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

https://www.chaijs.com/

First of all, make sure you have installed Node in your computer, you can get it here: https://nodejs.org

In your workspace folder, run the next command to init a node package, and complete the requested parameters.

npm init

Run the following command to install Mocha and Chai as a dev dependency

npm install --save-dev mocha chai

Let’s write a simple function that adds 2 numbers

const add2Numbers = (x, y) => {
return x + y;
};

Let’s write the test for that function

// First we have to require chai
const chai = require("chai");


describe("add2Numbers()", () => {
// Description of the test
it("should add 2 numbers", () => {
const x = 1;
const y = 2;

const sum = x + y;

const sumByFunction = add2Numbers(x, y);

// Our assert function
chai.expect(sumByFunction).to.be.equal(sum);
});
});

Next step is to run our tests, go to package.json, and add the “directories” property if not set already. Inside directories, we add another key named “test” that will have the value of the directory where we are saving our test files. Also, we need to add our test script, that will be just “mocha”.

package.json
{
.
.
.
"directories": {
"test": "test"
},
"scripts": {
"test" : "mocha"
}
.
.
.
}

So far, our project structure should look like this.

src
- package-lock.json
- package.json
- tests
- - example.test.js

We do the tests running the next command

npm test

The output should look like this

   mocha 
add2Numbers()
✓ should add 2 numbers
1 passing (11ms)

So far so good! Now you know how to write tests in Node.

You can find the code here https://github.com/samosunaz/node-tests