2 Getting started with testing Flashcards

1
Q

How to you declare a test?

A

Write a function that begins with a Test prefix and takes a testing.T parameter.

func TestName(t *testing.T) {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Test source files have what suffix?

A

A test file ends with a _test.go suffix.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What function logs a message to test output?

A
t.Log(args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What function logs a formatted message to the test output?

A
t.Logf(format string, args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What function marks a test as failed, but the test keeps running?

A
t.Fail()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What 3 phases can a test be written with?

A

Arrange
Act
Assert

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to create a simple error?

A

errors.New(“an error occurred”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What function stops a test executing immediately?

A
t.FailNow()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What function is equivalent to Log and FailNow?

A
t.Fatal(args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What function is equivalent to Logf and FailNow?

A
t.Fatalf(format string, args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What type can represent any type?

A
any
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What parameter indicates a function accepts a variable number of arguments of any type?

A
...any
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What function is equivalent to Log and Fail methods?

A
t.Error(args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What function is equivalent to Logf and Fail methods?

A
t.Errorf(format string, args ...any)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the most commonly used naming convention for testing in Go?

A

got-want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In the testing package what belongs to a single Goroutine?

A

A panic and each test has it’s own Goroutine.