Documentation

Overview

    Package subtest provides a TestContext to subtests which handles cleanup, and provides a testing.TB, and context.Context.

    This package was inspired by github.com/frankban/quicktest.

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func Run

    func Run(t *testing.T, name string, subtest func(t TestContext)) bool

      Run a subtest. When subtest exits, every cleanup function added with TestContext.AddCleanup will be run.

      Example (TableTest)
      Output:
      
      
      Example (TestSuite)
      Output:
      
      

      Types

      type TestContext

      type TestContext interface {
      	testing.TB
      	// AddCleanup function which will be run when before Run returns.
      	AddCleanup(f func())
      	// Ctx returns a context for the test case. Multiple calls from the same subtest
      	// will return the same context. The context is cancelled when Run
      	// returns.
      	Ctx() context.Context
      	// Parallel calls t.Parallel on the testing.TB. Panics if testing.TB does
      	// not implement Parallel.
      	Parallel()
      }

        TestContext provides a testing.TB and a context.Context for a test case.

        Source Files