go-unitest

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2021 License: Apache-2.0

README

GO-UNITEST Go Report Card GitHub go.mod Go version License

Example

Sample Desc
simple Simple unitest that most of us already know and get used to it.
dependency-injection Robust unitest that have connection to other layer from result test. It's not merely mock the result, but it will pick the result from dest's test.

ex: if you have changes in usecase, you probably not only fix the test in usecase, but also in delivery since delivery test pick the mock result from usecase.
mock-vendor To do some mock, we need interface. Sometimes there's some vendor who only provide struct with the functions. To mock that we need to step back, generate our own interface and store it.

Rule of thumb

About Desc
Using test name convention Our testName using this convention. Sometimes the devs tend to forget to do it properly, therefore having this builder will reduce the problem.
Centralized data test Sometimes we need to reuse data over and over again which lead dry in unitest. To avoid that, we need to centralized data somewhere. In here, we put under dir test-data
Don't test private function If there's part of code can't covered in private function from public function test then perhaps that part doesn't needed / can't be reached.
Avoid mock.Anything This is powerful yet will make devs not know the exact param. Sometimes there's case that we need this such as random.

Directories

Path Synopsis
example
dependency-injection/delivery/num/http/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
dependency-injection/repository/num/redis/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
dependency-injection/usecase/num/component/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
mock-vendor command
mock-vendor/person
NOTE: we don't want to use DelName().
NOTE: we don't want to use DelName().
mock-vendor/person/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
simple command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL