liveBook · Manning

Test

As explained in gRPC Microservices in Go

Testing is the systematic evaluation of software behavior against expected results or properties.

Testing systematically evaluates software behavior against expected results or properties. In a microservice system, it isolates a service such as Order to provide faster feedback and reduce delivery cost compared with manually exercising the full flow. section 7.0 section 7.2

Select a strategy according to scope, feedback speed, and dependency cost:

  • Use unit tests to verify scenarios within a service or module; favor them for fast feedback and lower infrastructure cost. section 7.6
  • Use integration tests to verify that two modules work together, commonly testing a data layer against a real database. section 7.6
  • Use end-to-end tests to verify a flow across all available services, accepting broader environment involvement. section 7.6
  • Use mocks when real dependencies would slow feedback; use test containers when the real dependency is valuable to the integration test. section 7.2.2

Structure an automated test around four phases:

  • Setup dependencies and initialize the system under test (SUT). section 7.2.2
  • Invoke the SUT operation under test. section 7.2.2
  • Verify actual and expected results with assertions. section 7.2.2
  • Tear down resources that are no longer needed, such as a temporary database. section 7.2.2

Testing Fibonacci and Order

A Go test can call Fibonacci(3), expect 2, and verify the result with testify assertions in a _test.go file executed by go test. For an Order service backed by MySQL, either start a database through test containers or mock database calls when rapid feedback matters more. section 7.2.2 section 7.2.2

// math_test.go
package math
 
import (
    "testing"
 
    "github.com/stretchr/testify/assert"   #1
)
 
func TestFibonacci(t *testing.T) {
    actual := Fibonacci(3)
    expected := 2
    assert.Equal(t, actual, expected)
}

Browse the compact Go unit test that invokes Fibonacci and checks its expected result. section 7.2.2

How gRPC Microservices in Go covers it

How deep it goes
Explains strategies, test workflow phases, dependency choices, test pyramids, coverage, and CI verification without detailing framework internals.
Examples
Demonstrates Fibonacci assertions in Go and contrasts mocked or containerized MySQL dependencies for an Order service.
What it assumes
Assumes basic service code and dependencies, while defining the SUT and introducing setup, invocation, verification, and teardown.
What you can do after
Apply it via go test, testify, mocks, or test containers to verify service scenarios and dependency integrations.
How it connects
Connects unit testing with integration testing, end-to-end testing, mocking, test containers, test coverage, and CI pipelines.

Also explained in

Compare how 53 books explain test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.