Recall & Review
beginner
What is the purpose of the
testing package in Go?The
testing package provides tools to write and run automated tests for Go code, helping ensure code correctness.Click to reveal answer
beginner
How do you write a basic test function using the
testing package?Create a function starting with
Test and accepting t *testing.T as a parameter. Example:<br>func TestExample(t *testing.T) { /* test code */ }Click to reveal answer
intermediate
What method do you use to report a test failure inside a test function?
Use
t.Error() or t.Errorf() to report a failure but continue running the test, or t.Fatal() / t.Fatalf() to stop the test immediately.Click to reveal answer
beginner
How do you run tests in a Go project from the command line?
Use the command
go test in the directory containing the test files. It automatically finds and runs tests.Click to reveal answer
advanced
What is the role of the
TestMain function in Go testing?TestMain(m *testing.M) allows setup and teardown before and after running tests. It controls the test execution flow.Click to reveal answer
Which prefix must a function have to be recognized as a test by the Go
testing package?✗ Incorrect
Test functions must start with 'Test' to be run by the Go testing tool.
What parameter type does a Go test function receive?
✗ Incorrect
Test functions receive a pointer to testing.T to report test status.
Which command runs all tests in the current directory in Go?
✗ Incorrect
go test runs all tests in the current directory.What does
t.Fatal() do inside a test?✗ Incorrect
t.Fatal() logs the error and stops the test immediately.What is the purpose of
TestMain in Go tests?✗ Incorrect
TestMain allows setup and teardown around tests.Explain how to write and run a basic test using the Go
testing package.Think about the function name and parameter, then how to run tests.
You got /3 concepts.
Describe the difference between
t.Error() and t.Fatal() in Go tests.Consider what happens after reporting an error.
You got /2 concepts.