2 Getting started with testing Flashcards
How to you declare a test?
Write a function that begins with a Test prefix and takes a testing.T parameter.
func TestName(t *testing.T) { }
Test source files have what suffix?
A test file ends with a _test.go
suffix.
What function logs a message to test output?
t.Log(args ...any)
What function logs a formatted message to the test output?
t.Logf(format string, args ...any)
What function marks a test as failed, but the test keeps running?
t.Fail()
What 3 phases can a test be written with?
Arrange
Act
Assert
How to create a simple error?
errors.New(“an error occurred”)
What function stops a test executing immediately?
t.FailNow()
What function is equivalent to Log and FailNow?
t.Fatal(args ...any)
What function is equivalent to Logf and FailNow?
t.Fatalf(format string, args ...any)
What type can represent any type?
any
What parameter indicates a function accepts a variable number of arguments of any type?
...any
What function is equivalent to Log and Fail methods?
t.Error(args ...any)
What function is equivalent to Logf and Fail methods?
t.Errorf(format string, args ...any)
What is the most commonly used naming convention for testing in Go?
got-want