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