Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Unit testing in an MVP pattern


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.

Getting ready

Get the code from the Login form with Model View Presenter recipe.

How to do it...

Perform the following steps:

  1. Create the LoginViewImplTest class inside the test folder:

    public class LoginViewImplTest { }
  2. 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();
       ...