Pattern: Test Bomb
Intent
To safely disable a test, which can't be fixed right now for some reasons.
Also Known As
Time Bomb
Motivation
Sometimes perfectly good test starts to fail and for some reasons fixing the test right now is not feasible or possible. This can happen because: developer team is under tremendous time pressure and does not have time to investigate test depends on some external infrastructure that is expected to be down test fails because of refactoring in progress and it is not clear how to best fix it yet.
Most team pick one of two options:
- do nothing and keep test failing. This will introduce a Failing Test antipattern.
- disable a test in build file/configuration file or in the test source code. This will introduce a Disabled Test antipattern and usually the test will be forgotten for a long time.
Test Bomb provides a better alternative.
Applicability
Use Test Bomb when there's a failing test, but it can't be fixed right now.
Description
Instead of permanently disabling a test, disable it temporary, so that it starts failing again after some time. This might require special tool support or code changes.
Example
// AccountManagerTest.java
public void testAccountManager() {
if (TestUtils.bomb(1, 9, 2012)) return; //bomb till 1 sepetmber 2012
//some account manager testing code goes here
}
// TestUtils.java
public static void bomb(int day, int month, int year) {
if (DateUtil.isInThePast(day, month, year)) return false;
return true;
}
Related Antipatterns
- Failing Test - ignoring failing test keeps build failing.
- Disabled Test - permanently disabled tests are usually forgotten.
- Flaky Test - flaky tests are commonly disabled by developers when there is no time to fix them.