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

Application Lifecycle Management

Search In Project

Search inClear

Tests #17042/HEAD / v10
Tags:  not added yet

DSL Root Element tests{}

The tests element is used to create a set of tests for a single OMS component. A "single" component can be considered one component or a compound component. A model essentially is a compound component. However, tests is intended to focus on testing parts of a model.

Element tests{}

Specification

Name
tests - Defines a set of tests for a single component

Properties Description Type Occurrences
name Name of the test set String Zero or one, optional

Sub Elements Occurrences
resource One or many
model{} Exactly 1, required
test One or many

Parent
Root element

Notes

  • Other general elements such as outputstrategy are not recommended for unit testing. They introduce dependencies to external resources, such as files and folders. Components should be tested with no external resource dependencies.

Example

tests(name:"Example 9 Testing") {
    // 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
          }
    )
}