3 Fighting with Complexity Flashcards

1
Q

How to you mark a function as a test helper?

A

Include a call to t.Helper() in the function.

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

What does t.Helper() do?

A

The caller, instead of the helper, will report the failure.

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

What is the idiomatic solution to the duplicate tests problem?

A

table-driven testing.

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

What are the advantages of table-driven-testing?

A
  • Less code
  • Less cognitive load
  • Easy to add new test cases
  • Easier to see corner cases are covered
  • Avoids adding helper methods for shared logic
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a test that you can run within a top-level test function in isolation?

A

A subtest.

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

What Go command runs tests and shuffles the order they run in?

A
go test -v -shuffle=on
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

After running a shuffled test how to I rerun again in that same order?

A

Take the number output in the first run and use it with the shuffle flag.

go test -v -shuffle=1624629565232133000
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do I run a subtest?

A

t.Run(name string, func (t *testing.T) {…} )

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

What is a higher order function?

A

a function that returns another function.

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

Declare a table test who’s subtest would be run in random order?

A

Use a map instead of an array struct.
~~~
tests := map[string]struct{..}
~~~

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