#Unit Test
6 articles
11 Add Unit Tests Using Mockery
At this stage we will need the following dependencies
brew install mockery
go get github.com/stretchr/testify
go mod tidy
go mod vendor
go get github.com/DATA-DOG/go-sqlmock
In this project we will try to create unit tests using a mocking library with the name mockery
. This library is widely used by golang developers because of its ease of use and has the advantage of features that can cover all the necessary unit tests. If you have used unit tests in golang, you may already know this library but if you want to get more references, Santekno has also provided previous posts including:
Techniques for Creating Mocking Unit Tests in Golang
When we create a function or code, sometimes we have difficulty carrying out unit tests at several points that we cannot cover with unit tests. So here are several technical ways to carry out unit tests using the mocking technique. But actually we can also use third-party which is already available in several libraries so we just need to use it straight away.
How to Create Integration Tests in Golang
Carrying out integration tests for APIs means that we must at least be able to run the application first so that integrated testing can be carried out.
We need to prepare several cases, test cases that cover the needs of the integration test. For example, the API Endpoint' that we have worked on has a
database,
cache` or other external resource that is related to the continuity of the API Endpoint.
How to Create Unit Tests Using the moq Library in Golang
Carrying out unit tests using this mocking method is usually used if several functions have been carried out in interface
format so that we can assume that if we call the interface
function we believe that it should produce the correct program.
How to Create Benchmark Units in Golang
The testing
package in Golang Programming, apart from containing tools for testing, also contains tools for benchmarking. The way to create a benchmark itself is quite easy, namely by creating a function whose name begins with Benchmark
and whose parameters are of type *testing.B
.
How to Create Unit Tests in Golang
Unit Testing Using the Go Library
programming is not easy, even the best programmers cannot write programs that work exactly as desired every time. Therefore, an important part of the software development process is testing. Writing tests
for our code is a good way to ensure quality and increase reliability.