IzPack tests

The IzPack revamp comes with more tests which have been used for the refactoring.

Introduction

New code have been written with unit tests and integration tests has been made to check the overall sanity of the application.
The integration test execute a compilation of an IzPack installer, load the generated jar in the classpath and execute the installer. When the installer frame appear, a swing robot interact with the interface to realize the installation.
This system allows to launch almost real installation and check live result automatically on several platform.

Tests tools

We use several testing tools

  • fest as the swing robot for interface interactions
  • TestNG in the izpack-test module which provides interesting features for integration tests like dependent test method.
  • Hamcrest to realise assertions with assertThat(). See hamcrest tutorial for more details. It is quite powerful thanks to its matcher system.
  • Mockito as the mock framework. It allows you to creates, control and check mocks.
  • JUnit
    Note: Junit 4 imported several classes from Hamcrest to a different package and has an implicit dependency to Hamcrest. Therefore, keep dependencies to JUnit and Hamcrest in sync, for not pulling in incompatibilities,
    Current state: JUnit 4.10 depends on Hamcrest 1.1.

Running Tests

Maven execution

Tests are automatically run by maven during the build. Just run "mvn install" to run tests on the project.

NOTE: GUI tests are disabled by default. To run these, use:

mvn -Pwith-gui-tests install
IDE execution

You can run tests directly in your IDE.
If you use Eclipse, you need to install the TestNG eclipse plugin to run tests in the test-module.

Headless execution

It is possible to run graphical tests on a headless environment using Xvfb. Given that you have xvfb installed, you simply need to run
Maven build using xvfb

xvfb-run -s "-screen 0 1280x1024x24" $MAVEN_BIN/mvn clean install

You can also run headless tests from your IDE by starting a Xvfb server and specifying the DISPLAY variable to the DISPLAY created by the xvfb server.

Skip graphical tests

If you don't have Xvfb or don't want to run graphical tests, you can use the bamboo profile with maven (use -Pbamboo).
This profile run a special testNG suite excluding all tests using graphical elements.

Writing tests

First, you need to narrow what kind of tests you want.

Type of tests

Unit testing

Ideally, a test is considered as a unit if there is only one class and one method under test, thus, they are small and fast but you need to restrict the test to a minimum and mock others dependencies.

A test is not a unit test anymore when there are :

  • i/o processing (write or read file)
  • access to a database
  • network access
  • More than one real component
  • Gui display and interaction

Integration tests

Basically, everything that is not a unit test is an integration tests.

They are slower to run since there is more components to manage or there is some i/o processing. To run integration tests use the command below:

mvn -Prun-its install

End-to-end tests

Those tests bootstrap and execute the entire application. They are heavy and keep to a minimum but they are used to execute end-to-end test.

In the case of IzPack, functional tests run an installer compilation, load the created jar in the classpath and run the installer. Currently, they are installation which are tested :

  • A stupid installation : It just displays an hellopanel and a finishPanel
  • A basic installation : It uses the sample installation of IzPack
  • The IzPack installation : It runs the IzPack self-installer

Good practices and advices

How to use PicoContainer with JUnit