Thursday, August 4, 2016

Hello World with React

First create a folder called hello-world-react and initialize npm within the folder.
For this demo, you must have installed webpack. Next install following node packages.
Next create following files in  the project folder.
Edit webpack.config.js file like below.
index.html file content should be like below.
Next edit App.js file like below.
Now we need to change main.js file accordingly.
Next we need to edit package.json file to add start script.
Run our first react project using following command.
In browser for localhost:8888, and you will see following content. Now you can edit your project content and it will automatically reder in browser.

Thursday, June 9, 2016

Test Coverage In Go

In my previous post I showed how to write basic tests in Golang. In this post we will go through how to identify test coverage in Golang with it's inbuilt commands. I will continue with the source code from previous post.
First run following command. Output is about basic details of test coverage in our current code base.
Next add new function like below.
Again run command for test coverage. This time output is different.
If you need to get function wise output, then we need to run following command.
Further if you need to export those data into html, you can use following command. It will output the details into your default web browser.
The output is like below.

Testing in Golang

Golang is one of the programming language which use convention over configuration. In Go application, we can write a test file by adding Test suffix to test source file. Then this file will be ignored in Go build process. And also test runner can inspect test functions in these files and execute tests.
There are three types of tests in Go.

  • Basic Tests (Regular tests)
Basic tests are for identify application is performing accurately. These tests required to have Test prefix in test functions.
  • Benchmark Tests

Benchmark test are for identify performance with related to limits. These tests required to have Benchmark prefix in functions.

  • Example Tests
Example tests are integrated with GoDoc tool. These test required to have Example as prefix.
In this post, we will create a Basic test. We are going to do Test Driven Development, therefore we need to first write test functions.
Then write the actual code.
Now using following command we can run test runner. The output will be like below.
Next will change result comparing value for demonstration purpose. Then our test function become incorrect.
Run go test command again. Then output is like below.