updates
This commit is contained in:
parent
8a4743a1d2
commit
2f4206a8e6
10
README.md
10
README.md
@ -20,7 +20,9 @@ go install github.com/matryer/moq
|
||||
|
||||
Mocking interfaces is a nice way to write unit tests where you can easily control the behaviour of the mocked object.
|
||||
|
||||
Moq creates a struct that has a function field for each method, which you can declare in your test code:
|
||||
Moq creates a struct that has a function field for each method, which you can declare in your test code.
|
||||
|
||||
This this example, Moq generated the `EmailSenderMock` type:
|
||||
|
||||
```go
|
||||
func TestCompleteSignup(t *testing.T) {
|
||||
@ -28,7 +30,7 @@ func TestCompleteSignup(t *testing.T) {
|
||||
called := false
|
||||
var sentTo string
|
||||
|
||||
mockedEmailSender = &SenderMock{
|
||||
mockedEmailSender = &EmailSenderMock{
|
||||
SendFunc: func(to, subject, body string) error {
|
||||
called = true
|
||||
sentTo = to
|
||||
@ -46,6 +48,10 @@ func TestCompleteSignup(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func CompleteSignUp(to string, sender EmailSender) {
|
||||
// TODO: this
|
||||
}
|
||||
```
|
||||
|
||||
The mocked structure implements the interface, where each method calls the associated function field.
|
Loading…
Reference in New Issue
Block a user