import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) type MyTestSuite struct { suite.Suite } func (suite *MyTestSuite) TestSomething() { // Set up test key := "mykey" value := "myvalue" // Log key/value pair suite.T().Log(key, value) // Assert something assert.Equal(suite.T(), 1, 1) // Require something require.True(suite.T(), true) } func TestSuite(t *testing.T) { suite.Run(t, new(MyTestSuite)) }
suite.T().Logf("The %s is %d", "answer", 42)
func (suite *MyTestSuite) TestSomething() { // Set up test key := "mykey" value := "myvalue" // Run sub-test suite.T().Run("subtest 1", func(t *testing.T) { t.Log(key, value) assert.True(t, true) }) // Assert something assert.Equal(suite.T(), 1, 1) // Require something require.True(suite.T(), true) }In this example, we define a sub-test within the main test function using `suite.T().Run()`. Within the sub-test, we log a key/value pair using `t.Log()`, and add an assertion. Overall, TB Log is a useful logging library for test output in Go, and can help in generating an organized and informative report at the end of the test run.