Ega Prasetya
Posted on March 5, 2021
Okay so in the first write i gonna to show you how to implementation Unit Testing in Go, absolutely this is very ez to learn. So lets do it.
Create Package
so i created package name is helper, but if you wanna to create another package name it`s not a problem.
Like the examples above, i made function simple named Hello World. if we`re trying to test it, then it should be done with Test.go.
Next, Go has a method (t *testing.T) and then follow the code below.
Result
if we wanna to run this code, we got to the helper folder first.
In above, we create a logic which only contains an error by using the panic function.
In Go, we can perform an error other than panic, we can use t.Fail() and t.FailNow() .
It`s the difference when using t.Fail() and t.FailNow()
First, we change in Hello_World.go
Next, we create other function in Hello_World_test.go
Result :
So we got this, thx for read and sorry for the mistakes, Enjoy.
Posted on March 5, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.