liveBook · Manning

Evaluation suite

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

A test suite is an organized collection of related tests, commonly accompanied by shared setup and teardown behavior.

A test suite groups related tests that share setup or teardown, so each case can focus on behavior instead of repeating fixture and mock initialization. section 6.5.1

In Go, Testify wraps standard testing in a suite struct. SetupTest runs before each test; setup and teardown hooks reduce duplication and can reset mocks. section 6.5.1

Testing a translation client

A remote-service suite initializes a mock client and service for each test. A client suite starts a fake HTTP server and tests successful, missing-result, and error responses. section 6.5.1 section 6.6

Listing 6.13 remote_translator_test.go
package translation_test
 
import (
    "context"
    "errors"
    "testing"
 
    "github.com/stretchr/testify/mock"
    "github.com/stretchr/testify/suite"
    "github.com/holmes89/hello-api/translation"
)
 
func TestRemoteServiceTestSuite(t *testing.T) {                              #1
    suite.Run(t, new(RemoteServiceTestSuite))
}
 
type RemoteServiceTestSuite struct {                                         #2
    suite.Suite                                                              #3
    client *MockHelloClient
    underTest *translation.RemoteService
}
 
func (suite *RemoteServiceTestSuite) SetupTest() {                           #4
    suite.client = new(MockHelloClient)
    suite.underTest = translation.NewRemoteService(suite.client)
}
 
type MockHelloClient struct {                                                #5
    mock.Mock                                                                #6
}
 
func (m *MockHelloClient) Translate(word, language string) (string, error) { #7
    args := m.Called(word, language)                                         #8
    return args.String(0), args.Error(1)                                     #9
}

See how a Testify suite embeds suite.Suite and initializes its mock client and service in SetupTest. section 6.5.1

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Explains suite embedding, per-test setup, and lifecycle hooks, while deferring additional setup and teardown commands.
Examples
Uses Go suites for a remote translation service and fake HTTP client, including successful, missing-result, and error cases.
What you can do after
Apply it via Testify to group tests and initialize shared dependencies before each test.
How it connects
Connects suites to mocks, interfaces, stubs, fakes, and unit and integration testing.

Also explained in

Compare how 11 books explain evaluation suite →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.