Lecture 6-Test smells Flashcards
(24 cards)
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.
Eager test vs Assertion roulette
Eager test –> testing multiple functionality
Assertion roulette–> one functionality but many assertions without explanation
When do we use Indirect testing?
When a test class contains methods that actually perform tests on other objects.
What is the solution of Indirect testing (2 methods)?
1.Apply Extract Method to move indirection to the appropriate test class.
2.Apply Move Method on that part of the test.
When do we use For testers only?
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
What is the solution of For testers only (1 method) ?
Apply Extract Subclass to move methods from class to a new subclass in test code and use that subclass to perform the tests on.
When do we use Sensitive Equality?
Whenever the toString method for an object is changed and tests start failing.
What is the solution of Sensitive Equality?
Apple Equality Method (assertEquals) to replace toString equality checks by real equality checks.
When do we use Test code duplication?
When test code may contain undesirable duplication. The parts that set up test fixtures are susceptible to this.
What is the solution of Test Code Duplication(1 method)?
Use Extract Method.