Run parallel - or steer concurrency

AludraTest supports definition of concurrency characteristic on every test run node by annotation.

Test run nodes are:

  • test method
  • test suite
  • test class

Annotations for concurrency characteristic are:

  • @org.aludratest.testcase.Parallel defines parallel execution
  • @org.aludratest.testcase.Sequential defines sequential execution

This gives the freedom, to execute e.g. health check or smoke test suites first and afterwards all other tests. It also allows to define an explicit sequence of name tests, if necessary.

Behavior and Inheritance

AludraTest will use the parse the test execution tree and use the most narrow definition of execution order:

  1. If a method is annotated, this is used in any case.
  2. If a method is not annotated, order is derived from class
  3. If the method is not annotated and also the class is not annotated, the suite is used
  4. If neither the method, the class nor the suite is annotated, the nearest suite in the test suite hierarchy above is used
  5. If there is no annotation in the test suite hierarchy, the configuration value is used
  6. Configuration default value is parallel execution

Test Method

A test method may be parameterized with test data and data source. AludraTest will call the test method for each data set the data source provides exactly one time. If there are ten data sets, the method is called ten times with the ten unique data sets.

By adding the annotation @Parallel to the method's definition, AldraTest will run the ten combinations of method and data set parallel. Example:

import org.aludratest.testcase.AludraTestCase;
import org.aludratest.testcase.Parallel;
import org.aludratest.testcase.Sewuential;
import org.aludratest.testcase.data.Source;
import org.aludratest.testcase.Test;

public class MyTestClass extends AludraTestCase {

  // this test derives concurrency from class and test suite hierarchy
  @Test
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void derivedTest(TestData data) {
  	logInfo("test data: " + data);
  }

  // this test runs parallel
  @Test
  @Parallel
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void parallelTest(TestData data) {
  	logInfo("test data: " + data);
  }
  
  // this test runs sequential
  @Test
  @Sequential
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void sequentialTest(TestData data) {
  	logInfo("test data: " + data);
  }
}

Test Class

Test classes can be annotated with concurrency characteristics. This will be applied:

  1. to execution order of different test methods
  2. to execution order of single test methods
Parallel Test Class

The following parallel class will try to assign the runs to all three test methods parallel. Additionally the method derivedTest() will run it's data sets parallel. According available threads, all three will start parallel, but sequntialTest() will finish last, as their data sets are executed sequentially.

import org.aludratest.testcase.AludraTestCase;
import org.aludratest.testcase.Parallel;
import org.aludratest.testcase.Sewuential;
import org.aludratest.testcase.data.Source;
import org.aludratest.testcase.Test;

@Parallel
public class ParallelClass extends AludraTestCase {

  @Test
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''derivedTest'''(TestData data) { logInfo("test data: " + data); }

  @Test
  @Parallel
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''parallelTest'''(TestData data) { logInfo("test data: " + data); }
  
  @Test
  @Sequential
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''sequentialTest'''(TestData data) { logInfo("test data: " + data); }
}

Sequential Test Class

The SequntialClass{} will run the test methods in fixed sequence:

  1. All data sets of derivedTest() sequentially, then
  2. All data sets of parallelTest() parallel, as force by method annotation. Then
  3. All data sets of sequentialTest() sequentially

import org.aludratest.testcase.AludraTestCase;
import org.aludratest.testcase.Parallel;
import org.aludratest.testcase.Sewuential;
import org.aludratest.testcase.data.Source;
import org.aludratest.testcase.Test;

@Sequential
public class SequentialClass extends AludraTestCase {

  @Test
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''derivedTest'''(TestData data) { logInfo("test data: " + data); }

  @Test
  @Parallel
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''parallelTest'''(TestData data) { logInfo("test data: " + data); }
  
  @Test
  @Sequential
  @Source(uri="ExcelFileWith10Lines.xls", segment="sheet1")
  public void '''sequentialTest'''(TestData data) { logInfo("test data: " + data); }
}

Test Suite

Test Suites annotated with @Parallel or @Sequential behave the same like classes, but apply the mechanism to test classes and test suites.

import org.aludratest.Suite;

@Parallel
@Suite({
  MyTestClass1.class,
  MyTestClass2.class,
  NestedTestSuite.class
})
public class MyTestSuite {}