A Golang library for generating interface stubs. Stubs make it easy to test a project in a table-driven style.
For an example of an easy-to-test approach, refer to the example directory.
Currently, the stubgen doesn't support generic interfaces.
go install github.com/Gamazic/stubgen@latestHave a Go module with the following content:
mymodule.go
package testdata
type MyInterface interface {
Func(int, bool) error
}To generate a stub for the file, use the command with the --inp-file argument:
stubgen --inp-file testdata/testfile.goResult in console:
// Code generated by stubgen; DO NOT EDIT.
package testdata
type StubMyInterface struct {
FuncRes0 error
}
func (s StubMyInterface) Func(_ int, _ bool) error {
return s.FuncRes0
}Alternatively, you can provide source code from stdin:
cat mymodule.go | stubgenTo save data in a file, use the --out-file argument:
stubgen --inp-file mymodule.go --out-file mymodule_stub.goFor more examples you can check example directory or testdata directory.