0
0
Goprogramming~5 mins

Writing basic test functions in Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AVerify
BCheck
CRun
DTest
Which package do you import to write test functions in Go?
Afmt
Bos
Ctesting
Dnet/http
What is the type of the parameter passed to a Go test function?
A*testing.T
Bint
Cstring
Dbool
How do you indicate a test failure inside a Go test function?
AAll of the above
Bt.Error()
Ct.Fatal()
Dt.Fail()
Which command runs tests in a Go package?
Ago run
Bgo test
Cgo install
Dgo build
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.