6 Testing (Frameworks) - G00fY2/android-mvp-wiki GitHub Wiki
6 Testing (Frameworks)
Writing software tests allows developers to write reliable and stable code. Even though writing software tests may appear to take more time, it actually can save you even more time in the long term. It is ideal to write software in test-driven development.
6.1 JUnit
JUnit is a popular framework to write repeatable tests in java projects. It played a prominent role in the development of many TDD frameworks. Since we are using MVP architecture, we do not need any specific Android Test Framework to test our business logic.
Junit tests ensures that:
- the code meets the concept and requirements
- the code works as expected (even in error cases)
- single components of a system work correctly
Benefits:
- saves time in the long term
- reduced errors in production code
- delimit errors, because of steady testing only last changes need to be debugged
6.2 Mockito
Unit tests supposed to test classes isolated from outer influences. Side effects from other classes or the system should be eliminated. Therefore those dependencies should be mocked. Here is where Mockito comes into play. Mockito is mock framework which can be used in conjunction with JUnit. Mockito allows you to create and configure mock objects.
Mock object:
- are a dummy implementation for an interface or a class
- the output of certain method calls can be defined
- are configured to perform a certain behavior