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

Application Lifecycle Management

Search In Project

Search inClear

Test #17066/HEAD / v10
Tags:  not added yet

DSL Element: test

The test element is used to create a single test case for an OMS model component.

Element test

Specification

Name
test - Defines a single test case for a component

Properties Description Type Occurrences
name Name of the test case (defaults: 'test-#' String Zero or one, optional
count Number of test case repetitions (default: 1) Positive decimal Zero or one, optional
timeout Maximum time in milliseconds to finish a test case (default: infinite); test fails if this time exceeds Positive decimal Zero or one, optional
pre Code block to run before execution Closure Zero or one, optional
post Code block to run after execution Closure Zero or one, optional
rangecheck Perform field range checks before and after execution (default: false) Boolean Zero or one, optional
ignore Ignore this test case on test execution (default: no) String Zero or one, optional
data Data set(s) to be passed to the component as input Array of <objects> No
expected Expected exception; the test succeeds if the exception is thrown, otherwise fails; the value is the full qualified class name as string String No

Parent
tests{}

Notes

  • If no test case name is given, a default generic name is provided with the actual test case number within the test set. The name for the first test case would the be 'test-1'
  • If both, the data property and the count is provided, the count property is ignored. The number of test repetitions will be determined by the provided data sets.
  • If the ignore property is provided with a string value, the test will not be executed, the string value will be printed out instead.
  • The rangecheck property might be combined with all other properties.

Example

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", 
          pre: { c ->             // this is a closure, 'c' is the component  
             c.tempC = 30         // fields can be accessed
          },         
          post:{ c -> 
             assert c.tempF == 86.0    // using groovy's asserts
    //       println c.tempF         // more statements can follow here.
          }
    )

    // Run this test against each input value from 'data'
    test(name:"2: multiple data input", 
          data:['tempC', 1, 2, 3, 5, 6, 7 ],   // data set with inputs
          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
          }
    )
}