Recall & Review
beginner
What is the purpose of a test function in Go?
A test function in Go checks if a piece of code works correctly by running it and verifying the results automatically.
Click to reveal answer
beginner
How do you name a basic test function in Go?
A basic test function name starts with
Test followed by a descriptive name, for example, TestAdd.Click to reveal answer
beginner
What package must you import to write test functions in Go?You must import the <code>testing</code> package to write test functions in Go.Click to reveal answer
beginner
What is the signature of a basic test function in Go?
A basic test function has the signature
func TestXxx(t *testing.T), where t is used to report errors.Click to reveal answer
beginner
How do you report a failure inside a Go test function?
Use
t.Error(), t.Errorf(), or t.Fatal() inside the test function to report a failure.Click to reveal answer
What prefix must a Go test function name start with?
✗ Incorrect
Go test functions must start with the prefix
Test to be recognized by the testing tool.Which package do you import to write test functions in Go?
✗ Incorrect
The
testing package provides tools to write and run tests in Go.What is the type of the parameter passed to a Go test function?
✗ Incorrect
The test function receives a pointer to
testing.T to report test status.How do you indicate a test failure inside a Go test function?
✗ Incorrect
You can use
t.Fail(), t.Error(), or t.Fatal() to indicate test failures.Which command runs tests in a Go package?
✗ Incorrect
The
go test command runs all test functions in the current package.Explain how to write a basic test function in Go from start to finish.
Think about the function name, parameter, and how to report errors.
You got /5 concepts.
Describe the role of the *testing.T parameter in Go test functions.
Consider how the test function communicates success or failure.
You got /3 concepts.