Sleepy Test
Definition:
Developers introduce this smell when they need to pause execution of statements in a test method for a certain duration (i.e., simulate an external event) and then continuing with execution. Explicitly causing a thread to sleep can lead to unexpected results as the processing time for a task differs when executed in various environments and configurations.
Code Example:
public void testEdictExternSearch() throws Exception {
final Intent i = new Intent(getInstrumentation().getContext(), ResultActivity.class);
i.setAction(ResultActivity.EDICT_ACTION_INTERCEPT);
i.putExtra(ResultActivity.EDICT_INTENTKEY_KANJIS, "空白");
tester.startActivity(i);
assertTrue(tester.getText(R.id.textSelectedDictionary).contains("Default"));
final ListView lv = getActivity().getListView();
assertEquals(1, lv.getCount());
DictEntry entry = (DictEntry) lv.getItemAtPosition(0);
assertEquals("Searching", entry.english);
Thread.sleep(500);
final Intent i2 = getStartedActivityIntent();
final List result = (List) i2.getSerializableExtra(ResultActivity.INTENTKEY_RESULT_LIST);
entry = result.get(0);
assertEquals("(adj-na,n,adj-no) blank space/vacuum/space/null (NUL)/(P)", entry.english);
assertEquals("空白", entry.getJapanese());
assertEquals("くうはく", entry.reading);
assertEquals(1, result.size());
}
References:
Quality attributes
- Code Example
- Cause and Effect
- Frequency
- Refactoring
An Exploratory Study on the Refactoring of Unit Test Files in Android Applications
Automatic Identification of High-Impact Bug Report by Product and Test Code Quality
Characterizing High-Quality Test Methods: A First Empirical Study
Handling Test Smells in Python: Results from a Mixed-Method Study
On the Distribution of “Simple Stupid Bugs” in Unit Test Files: An Exploratory Study
On the diffusion of test smells and their relationship with test code quality of Java projects
On the distribution of test smells in open source Android applications: an exploratory study
On the test smells detection: an empirical study on the jnose test accuracy
The secret life of test smells-an empirical study on test smell evolution and maintenance
Understanding practitioners’ strategies to handle test smells: a multi-method study