Home
Categories
Dictionary
Download
Project Details
Changes Log
What Links Here
How To
Syntax
FAQ
License

Ordering unit tests



Unit tests for rhe project are grouped in Categories, and allow to configure which categories will be run.

Also test methods for a test class can be ordered.

Ordering Unit Tests

To order Unit Tests methods in a Unit Test class, you have to:
  • Annotate the Unit test class with the org.mdiutil.junit.OrderedRunner annotation
  • Annotate each method in the Unit Test class with the org.mdiutil.junit.Order annotation

Example

If a test class has the two following methods:
   public class MyTest {

   @Test
   public void test1() {
   ...
   }

   @Test
   public void test2() {
   ...
   }
Nothing prevents the tests to be executed in the order test2() then test1(). To ensure that the order will be test1() then test2(), you can use:
   @RunWith(OrderedRunner.class)
   public class MyTest {

   @Test
   @Order(order=1)
   public void test1() {
   ...
   }

   @Test
   @Order(order=2)
   public void test2() {
   ...
   }

Group Unit Tests classes in Categories

To specify the categories on which a Unit Test belongs to, you should:
  • Annotate the Unit test class with the org.mdiutil.junit.CategoryRunner annotation
  • Add an org.mdiutil.junit.Category annotation for each category the Test Clas belongs to

OrderedRunners are CategoryRunners, so in many cases you only need to use an OrderedRunner.

Discovering categories

Discovering the categories file

To execute the Unit Tests which belong to one or several categories, you should use the categories.properties file in a org.mdiutil.junit.resources package in the unit tests directory.

File structure

The categories.properties file is a properties file with (key, value) pairs:
  • The key is the category name
  • The value is true or false: true indicates that the tests of the specified category should run, false that they should not run
Note that if no values are defined, all Unit tests will be run.

StrictMode

If the "strictMode" value is true, only tests which belong to all "true" categories will be executed. For example:
   strictMode=true
   editor=
   server=
   client=false
Only Unit Tests annotated by both "editor" and "server" will run.

ShowSkippedClasses

If the "showSkippedClasses" value is true, tests which are not executed will be set as Ignored. For example:
   showSkippedClasses=true
   editor=
   server=
   client=false
If "showSkippedClasses" value is false, then tests which are not executed will not be shown at all.

Note that by default showSkippedClasses is set as true. For example, in Netbeans, you would see this when executing the tests of the MDIUtilities project with the following configuration:
   strictMode=false
   long=
   pack=
   archi=false

Unit tests categories

Main Article: Unit tests categories

Using the DocGenerator class directly

When using the org.docgene.main.DocGenerator class directly to generate the wiki in Unit tests, you may have the following JVM error:
      Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
      junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.      
This error may be due to the fact that the class will exit by executing System.exit(0) exiting the JVM before the Unit test class could be executed completely. To fix this problem, you must use the DocGenerator.preventExit(true); before exeucting the generation.

For example:
      @Test
      public void testApply() {      
         String[] args = new String[2];
         URL url = this.getClass().getResource("input");
         File inputFile = new File(url.getFile());
         url = this.getClass().getResource("output");
         File outputFile = new File(url.getFile());
         args[0] = "-output=" + outputFile.getPath();
         args[1] = "-input=" + inputFile.getPath();
         DocGenerator gene = new DocGenerator();
         gene.preventExit(true);
         gene.launch(args); 
      }     

Categories: development

docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.