What are Unit Tests?
In computer programming, unit testing is a software testing method by which individual units of source code — sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures — are tested to determine whether they are fit for use
Developers use unit testing to validate individual functions, methods, modules, and packages. Unit testing aids in the discovery and elimination of issues early in the development cycle, as well as the prevention of regressions during refactoring. A decent unit test may also act as documentation for new developers on the project.
Goals
In this article, it is hoped that readers will get an insight into how to do basic testing on the Golang programming language using the standard package, namely “testing”.
Step 1: project structure
In a project belonging to someone else, surely you have encountered a file that has the prefix _test.go, right? and always in the same directory as the main file to be tested. At this time we will first create the project structure as below: