Lecture 6-Test smells Flashcards
What are the 11 test smells?
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
When do we use Eager Test?
When a test method checks several methods of the object to be tested.
What is the solution of Eager Test?
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.
When do we use Lazy Tests?
When several test methods check the same method using the same fixture.
What is the solution of Lazy Tests?
Use Inline Method to join them together.
When do we use Mystery Guest?
When a test uses external resources and introduces hidden dependencies.
What are the solutions of Mystery Guest(2 options)?
If we don’t need external resources:
-Refactoring: Inline Resource
If we need external resources:
-Setup external resource
When do we use Resource Optimism?
When non-deterministic behaviour is caused in test outcomes.
What is the solution of Resource Optimism?
Use Setup External Resource to allocate and/or initialize all resources that are used.
When do we use Test Run War?
When the tests run fine as long as you are the only one testing but fail when more programmers run them.
What is the solution of Test Run War?
Apply Make Resource Unique to overcome interference.
When do we use General Fixture?
When the setUp fixture is too general and different tests only access part of it.
What is the solution of General Fixture(2 methods)?
-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.
When do we use Assertion Roulette?
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.
What is the solution of Assertion Roulette?
Use Add Assertion Explanation to remove the smell –> optional first argument gives an explanatory message to the user when the assertion fails.