An open API service indexing awesome lists of open source software.

https://github.com/gamazic/stubgen

Go tool for generating stubs from interfaces
https://github.com/gamazic/stubgen

go stubs testing testing-tool

Last synced: about 1 month ago
JSON representation

Go tool for generating stubs from interfaces

Awesome Lists containing this project

README

          

# stubgen

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](./example) directory.

Currently, the `stubgen` doesn't support generic interfaces.

## Installation

```shell
go install github.com/Gamazic/stubgen@latest
```

## Example

Have a Go module with the following content:

`mymodule.go`
```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:

```shell
stubgen --inp-file testdata/testfile.go
```

Result in console:

```go
// 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:

```shell
cat mymodule.go | stubgen
```

To save data in a file, use the `--out-file` argument:

```shell
stubgen --inp-file mymodule.go --out-file mymodule_stub.go
```

For more examples you can check [example](./example) directory or [testdata](./testdata) directory.