Unit Testing Made Easy in Golang
After writing the code, testing is an essential part of the software development process.
Previously I covered the Fundamentals of Golang. After writing the code, testing is an essential part of the software development process. Testing refers to the process of checking whether all parts of code function well for different types of inputs.
If you are not a Medium member, continue reading this here: Unit Testing Made Easy in Golang
Personally, I feel testing is a tedious process and it daunts me. In this article, I will try to ease you into testing in Golang.
You can find the source code of the fundamentals of Golang and testing: https://github.com/Nidhi-Gahlawat/Golang
Writing Unit Test Cases
Unit testing in Go is an essential practice to ensure the correctness and reliability of your code. Go provides a built-in testing package called testing
that enables you to write and execute unit tests.
I will be using the following directory format. Here, myutil
has three files (mathutil.go
, myutil.go
, stringutil.go
) with different functionalities. main.go
uses the myutil
package’s functions to perform operations. all_test.go
would be used for testing.