Unit tests are testing code without any outside dependencies. The outside dependencies are usually mocked by framework such as, in this recipe, Mockito (https://code.google.com/p/mockito).
In this recipe, we will demonstrate testability of the MVP pattern, so we will write unit tests for the presenter and view. We will utilize the LoginPresenter
, UserService
, LoginView
, LoginViewHandler
, and LoginViewImpl
classes from the Login form with Model View Presenter recipe.
Perform the following steps:
Create the
LoginViewImplTest
class inside the test folder:public class LoginViewImplTest { }
Before we start testing, we need to set up the environment for running a unit test. Put the following code inside the
LoginViewImplTest
class:private LoginView view; private LoginViewHandler handler; @Before public void setUp() { view = new LoginViewImpl(); ...