Default Test
Definition:
By default Android Studio creates default test classes when a project is created. These template test classes are meant to serve as an example for developers when writing unit tests and should either be removed or renamed. Having such files in the project will cause developers to start adding test methods into these files, making the default test class a container of all test cases and violate good testing practices. Problems would also arise when the classes need to be renamed in the future.
Code Example:
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
@Test
public void shareProblem() throws InterruptedException {
.....
Observable.just(200)
.subscribeOn(Schedulers.newThread())
.subscribe(begin.asAction());
begin.set(200);
Thread.sleep(1000);
assertEquals(beginTime.get(), "200");
.....
}
.....
}
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
Handling Test Smells in Python: Results from a Mixed-Method Study
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