The basics of test-driven development in Vaadin
In this recipe, we will use the Test-driven Development (TDD) approach. It means we first write tests that fail and then we implement the code, which will be required by the tests. We will explore how we can test Vaadin applications with pure JUnit tests without any mocking frameworks.
We will create a simple login form. The login form will be kept quite simple in this example, so we can easily absorb the idea of developing Vaadin applications with unit tests.
A simple login screen is as follows:
Getting ready
First, we create a new Maven project. Inside the project, create a source folder for tests, as src/test/java
.
The project structure will be as follows:
Add JUnit dependency into the pom.xm
l file.
The latest version of JUnit is available at https://github.com/junit-team/junit.
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.9</version> </dependency>