dbtest
Database testing made easy in Go.
Features
-
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.
Installation
$ go get -u github.com/RussellLuo/dbtest
Usage
$ dbtest -h
dbtest [flags] source-file interface-name
-fmt
whether to make the test code formatted (default true)
-out string
output filename (default "./<srcPkgName>_test.go")
-spec string
the test specification in YAML (default "./dbtest.spec.yaml")
-tmpl string
the template to render (default to builtin template)
Examples
See examples.
Documentation
Check out the Godoc.