Complete the code to declare a basic test function in Go.
func TestAddition(t *[1]) {
// test code here
}The parameter for a test function in Go must be *testing.T to access test methods.
Complete the code to fail the test if the sum is incorrect.
func TestSum(t *testing.T) {
result := 2 + 2
if result != 4 {
t.[1]("Sum is incorrect")
}
}Fail or FailNow without a message.Error which does not accept formatting.t.Errorf reports an error but continues the test. It's commonly used to show failure messages.
Fix the error in the test function declaration.
func [1](t *testing.T) { product := 3 * 3 if product != 9 { t.Errorf("Product is wrong") } }
Test functions must start with 'Test' and be exported (capitalized) to run automatically.
Fill both blanks to check if the function returns the expected value and fail the test if not.
func TestSubtract(t *testing.T) {
result := subtract(5, 3)
if result [1] 2 {
t.[2]("Expected 2 but got different value")
}
}We check if the result is not equal to 2 using '!=' and report an error with t.Errorf.
Fill all three blanks to write a test that checks if the function returns true and fails the test if false.
func TestIsEven(t *testing.T) {
if  {
t.[2]("4 should be even")
t.[3]()
}
}t.FailNow() after reporting the error.The function isEven is called to check 4. If false, t.Errorf reports the error and t.FailNow stops the test immediately.