Lecture 6-Test smells Flashcards

1
Q

What are the 11 test smells?

A

1.Eager test
2.Lazy test
3.Mystery Guest
4.Resource optimism
5.Test run war
6.General fixture
7.Assertion roulette
8.Indirect testing
9.For testers only
10.Sensitive equality
11. Test code duplication

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

When do we use Eager Test?

A

When a test method checks several methods of the object to be tested.

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

What is the solution of Eager Test?

A

Separate the test code into test methods that test only one method –> use meaningful name to specify purpose

*can slow down tests due to increased setup/teardown overhead.

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

When do we use Lazy Tests?

A

When several test methods check the same method using the same fixture.

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

What is the solution of Lazy Tests?

A

Use Inline Method to join them together.

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

When do we use Mystery Guest?

A

When a test uses external resources and introduces hidden dependencies.

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

What are the solutions of Mystery Guest(2 options)?

A

If we don’t need external resources:
-Refactoring: Inline Resource

If we need external resources:
-Setup external resource

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

When do we use Resource Optimism?

A

When non-deterministic behaviour is caused in test outcomes.

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

What is the solution of Resource Optimism?

A

Use Setup External Resource to allocate and/or initialize all resources that are used.

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

When do we use Test Run War?

A

When the tests run fine as long as you are the only one testing but fail when more programmers run them.

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

What is the solution of Test Run War?

A

Apply Make Resource Unique to overcome interference.

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

When do we use General Fixture?

A

When the setUp fixture is too general and different tests only access part of it.

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

What is the solution of General Fixture(2 methods)?

A

-Use Extract Method only for that part that is shared by all tests.
-Use Inline Method to put the rest in method that uses it.

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

When do we use Assertion Roulette?

A

When theres a number of assertions in a test method that have no explanation –> if one of the assertions fails, you don’t know which one it is.

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

What is the solution of Assertion Roulette?

A

Use Add Assertion Explanation to remove the smell –> optional first argument gives an explanatory message to the user when the assertion fails.

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

Eager test vs Assertion roulette

A

Eager test –> testing multiple functionality

Assertion roulette–> one functionality but many assertions without explanation

17
Q

When do we use Indirect testing?

A

When a test class contains methods that actually perform tests on other objects.

18
Q

What is the solution of Indirect testing (2 methods)?

A

1.Apply Extract Method to move indirection to the appropriate test class.
2.Apply Move Method on that part of the test.

19
Q

When do we use For testers only?

A

When a production class contains methods that are only used by test methods:
(1) are not needed and can be removed
OR
(2) are only needed to set up a fixture for testing –>they usually have names or comments

20
Q

What is the solution of For testers only (1 method) ?

A

Apply Extract Subclass to move methods from class to a new subclass in test code and use that subclass to perform the tests on.

21
Q

When do we use Sensitive Equality?

A

Whenever the toString method for an object is changed and tests start failing.

22
Q

What is the solution of Sensitive Equality?

A

Apple Equality Method (assertEquals) to replace toString equality checks by real equality checks.

23
Q

When do we use Test code duplication?

A

When test code may contain undesirable duplication. The parts that set up test fixtures are susceptible to this.

24
Q

What is the solution of Test Code Duplication(1 method)?

A

Use Extract Method.