Warning
Currently very experimental.
- Type safety
- Generate mock objects mapping args and results
- Treat as stub objects is also possible
- Configure by yaml, don't use
//go:generate - There is no mather
- There is no method chaining loop
https://github.com/karamaru-alpha/mocka/tree/main/testdata
$ go install
$ mocka -h
Usage of mocka:
-c string
Config yaml file path (default ".mocka.yaml")Place .mocka.yaml in the root directory.
packages:
- github.com/karamaru-alpha/mocka/testdata:
all: true
- fmt:
interfaces:
- StringerExecute mocka command on the root directory.
$ mockam := testdata.NewMockHuman(t)
m.MockSay.Expect("Alice").Times(1).Return("Hello, Alice")m := testdata.NewMockHuman(t)
m.MockSay.ConditionalExpect(func(name string) bool {
return name == "Alice" || name == "Bob"
}).Times(1).Return("Hello, Alice or Bob")m := testdata.NewMockHuman(t)
m.MockSay.Stabilize(func(name string) string {
return "Hello, " + name
})| mocka | uber-go/mock | vektra/mockery | matryer/moq | gojuno/minimock | |
|---|---|---|---|---|---|
| Type safety | ✅ | ✅ | ✅ | ||
| Map args and results | ✅ | ✅ | ✅ | ✅ | |
| Treat as a stub | ✅ | 👑 | ✅ | ||
| Configure by yaml | ✅ | 👑 | |||
| No matcher | ✅ | ✅ | ✅ | ||
| No method loop | ✅ | ✅ |