Test with “Go”

Dulani Herath
3 min readMar 26, 2020

“Go” is a programming language which was introduced by Google. With compared to other basic programming languages (Java,C) Go is easy to understand and user-friendly. Go can be used for both development and testing. In most of the countries it became an upcoming programming language for software testing.

There are many testing frameworks in Go language.

  1. ginkgo
  2. go-carpet
  3. goblin
  4. gocheck
  5. testcase
  6. gofight

Above frameworks can be known as main Go testing frameworks and you can use any framework out of them. But in my point of view it is better to use VS code if you are planning to do test automation in Go language. VS code is a development tool, but we can use it when we are doing testing in Go language. If you are a beginner for automation testing and Go language, VS code is the best option.

In Go testing we have to create two files in VS code. Fist file should have the function. As an example, in unit testing we are mention the logic; function of the code. In here, we do the same. We mention the functions in the first file.

For get the output we import a library “fmt” . If we execute the code we should execute it as go run (file name).go

In the second file we write test cases.The second file should be named as the (name of the first file)_test. When we are doing testing we need to import “testing” library. We can write more than one test case in the same code. We can execute them separately or all together. If we execute test cases separately we should execute it as go test. If we execute all test cases together we should execute as go test -v.

These are two test case and I have executed all together and the output as below.

These functions are basic functions. You can learn more and apply them to complicated functions also. It make ease of your testing process and improve your knowledge.

--

--