In this case, we have mocked the method of Repository to return success with the data. Import ( "context" "time" "/amitshekhariitbhu/go-backend-clean-architecture/domain" ) type taskUsecase struct In this blog, we will learn to write the test by taking the Usecase as an example.Ĭonsider the TaskUsecase present inside the given project. In the project, we have Controller, Usecase, and Repository. Link to the project: Go Backend Clean Architecture. You can find the complete code for unit testing using the Testify and Mockery mentioned in the blog in the project itself. The project follows a clean architecture in Go Language. I will be using the below-mentioned project for the implementation part. So, let's start learning to use both packages to write tests in Go. It removes the boilerplate coding required to use mocks. Mockery package provides the ability to easily generate mocks for Golang interfaces using the testify package. mockery: A mock code autogenerator for Golang used in testing.Īs we know that the testify package is used for the purpose of the assertions. testify: A toolkit with common assertions and mocks that plays nicely with the standard library.These two packages are very useful during the testing of any Go files. In this blog, we will learn about writing the unit test with Testify and Mockery in Go (Golang) project. I am Amit Shekhar, a mentor helping developers in getting high-paying tech jobs.
0 Comments
Leave a Reply. |