Home
Categories
Dictionary
Download
Project Details
Changes Log
Who We Are
FAQ
License

Unit Tests



The J661 Project provides several thousands of Unit Tests defined using JUnit. The Netbeans ant built file allows to execute all these tests. Note that to have more information on how JUNit tests work, see JUnit concepts.

Ordering test methods

By default the execution of tests methods is not ordered. It is possible to enforce their order with a specific annotation.
      @RunWith(OrderedRunner.class)
      public class MyUnitTestClass {
      ...
      @Test
      @Order(order = 2)
      public void testMethod() {
      ...

Tests categories

Unit tests are grouped in categories. By default all tests will run, but if you want to set which categories of tests will run, you must modify the categories.properties file. By default, all Unit Tests will run, for all categories.

Code annotation

To specify a Unit Test as belonging to one or sevral categories, you have to add the following annotations before the test class declaration:
      @RunWith(CategoryRunner.class)
      @Category(cat = "archi")
      @Category(cat = "server")
      public class MyUnitTestClass {
or
      @RunWith(OrderedRunner.class)
      @Category(cat = "archi")
      @Category(cat = "server")
      public class MyUnitTestClass {

Framework specificities

In JavaFX, the JavaFX UI Framework must be started before the tests are executed. To allow this, if you are using Unit Tests using the JavaFX UI Framework, your must use the @RunWith(OrderedJavaFXRunner.class) rather than the @RunWith(OrderedRunner.class), or you will have an exception when trying to execute the tests. See Unit Tests UI Framework specificities for additional specifities depending on the UI Framework.

Run only one category of tests


If you want only Unit tests of a specific category to run, change the categories.properties file. For example:
      strictMode=false
      editor=true
      server=
      client=
      ...
In this example, only Unit Tests which are in the "editor" category will run.

Run several categories of tests

If you want only Unit tests of several specific category to run, specify more than one category in the categories.properties file. For example:
      strictMode=false
      editor=true
      server=true
      client=
      ...
In this example, only Unit Tests which are in the "editor" category or in the "server" category will run.

The strictMode allows to execute only Unit tests which belong in all the selected categories. For example:
      strictMode=true
      editor=
      server=true
      client=
      ...
      runtime=true
      ...
In this example, only Unit Tests which are in both the "server" category and the "runtime" category will run.

The strictMode allows to execute only Unit tests which belong in all the selected categories. For example:
      strictMode=true
      editor=
      server=true
      client=
      ...
      runtime=true
      ...
In this example, only Unit Tests which are in both the "server" category and the "runtime" category will run.

The headless tag allows to execute only headless Unit tests. For example:
      headless=true
      editor=
      server=
      client=
      ...
In this example, only headless Unit Tests will run. Note that you need to declare a test as headless by adding a "headless" category for this test.

Using the "force" value for the headless tag force all tests to be performed in a headless environment. It can be used to detect which tests are truly working in a headless environment.

Handling input events

See Handling Input events in Unit Tests.

See also


Categories: dev | junit

Copyright 2016-2017 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v2 licence