Database testing made easy in Go.
-
Declarative
Define the minimum test specification in a YAML-based DSL, then all tests can be generated automatically.
-
Customizable
You can specify your own Go template when generating tests.
-
Opinionated
- The database is a detail, which means the database-related code should always implement a Go interface.
- Run database tests against a real database, instead of relying on mocks.
- The limitation is that running tests in parallel is not supported.
- Use the same test fixture for all subtests of the same method under test.
- Only test the public methods, thus the generated tests are in a separate
_test
package. - Leverage TestMain to do global setup and teardown.
- Prefer table driven tests.
Make a custom build of protogo:
$ protogo build --plugin=github.com/protogodev/dbtest
Or build from a local fork:
$ protogo build --plugin=github.com/protogodev/dbtest=../my-fork
Usage
$ protogo dbtest -h
Usage: protogo dbtest <source-file> <interface-name>
Arguments:
<source-file> source-file
<interface-name> interface-name
Flags:
-h, --help Show context-sensitive help.
--out=STRING output filename (default "./<srcPkgName>_test.go")
--fmt whether to make the test code formatted
--spec="./dbtest.spec.yaml" the test specification in YAML
--tmpl=STRING the template to render (default to builtin template)
See examples.
Check out the Godoc.