You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

Component Test Suite

Series of tests for an OMS component.

Concept

OMS provides the 'tests' DSL element for verifying OMS components function as designed. Each test contains 'pre' and 'post' closure. The 'pre' closure sets inputs prior to execution of the component ('data' can substitute for 'pre' closure as shown in the example). The 'post' closure provides for verifying the output against asserted values or conditions.

Implementation

'Component' consumes 'TempC', executes a conversion method, and outputs 'TempF'.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
package ex09;

import oms3.annotations.*;

/**
 *
 * @author od
 */
public class Component {

    @In public double tempC;
    @Out public double tempF;

    @Execute
    public void run() {
        tempF = tempC * 9 / 5 + 32;
    }
}

The simulation file specifies a suite of three tests for 'Component'. The first test "1: single call" involves setting the 'TempC' parameter to 30 and asserting the output to be 86.0. The second test "2: multiple data input" involves a 'TempC' set of six values as input and printing the converted output values (presumably for manual comparison by the tester). The third test "3: randomized input" involves using a random number generator to create 'TempC' values between 10 and 15 as input and asserting the output to range between 50 and 59.

Each dot (period) in the output displayed in the diagram above represents a test instance meeting the assertion. A failed test would display as exceptions in logging information. (See what happens when contracting the asserted range to >50 && <55 in the third test).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This is a tests simulation type!
import static oms3.SimBuilder.instance as OMS3

OMS3.tests {
    // the component to test.
    model (classname:"ex09.Component")

    // Run this test once, the pre closure sets the @In before execution, 
    // the 'post' closure test the @Out after execution.
    test(name:"1: single call",
          // this is a closure, 'c' is the component  
          pre: { c ->
             // fields can be accessed
             c.tempC = 30
          },
          post:{ c ->
            // using groovy asserts
            assert c.tempF == 86.0
             //println c.tempF         
             //more statements can follow here.
          }
    )

    // Run this test against each input value from 'data'
    test(name:"2: multiple data input",
          // data set with inputs
          data:['tempC', 1, 2, 3, 5, 6, 7 ],
          post:{ c ->
             print c.tempF
          }
    )

    // Random number generator within the script.
    Random r = new Random()

    // Run this test 100 times, let a single test fail if it runs 
    // longer than 200ms. Create random 'tempC' values from 10 ... 15 degC as input;
    // test if the output falls in a expected range.
    test(name: "3: randomized input", count: 100, timeout:200,
          pre:{ c ->
             c.tempC = 10 + (5 * r.nextDouble())
          },

          post:{ c->
             assert c.tempF > 50 && c.tempF < 59
          }
    )
}