3.5. Specifying and Initializing the Object Under Test

There are several ways you can specify the object-under-test (the test instance).

3.5.1. Using new

You can use the new keyword in SIN expressions in the same manner as within Java code:

@Exemplar(instance="new Foo()")
public void fooMethod()

3.5.2. Using a supplied instance

As covered in the previous section you can use any SIN expression that returns an Object compatible with the class under test:

@Exemplar(instance="preinit")
public void foo()

3.5.3. Using a Sureassert named instance

As covered in the previous section you can use an expression that simply returns a named instance defined by another Exemplar, either via the name or instanceout property. You can use the re-execution postfix (“!”) to use a new copy of the instance by re-executing the referenced Exemplar:

@Exemplar(name="i1")
public Foo();
@Exemplar(instance="i1!")
public void foo();

3.5.4. Setting default field values via @TestState

You can initialize fields in test objects with default values by annotating the field with @TestState:

@TestState(value="l:i1,i2,i3")
private List<Message> messages;

3.5.5. Setting field values within the SIN Expression

You can set fields on objects using the SIN Expression field setter syntax:

@Exemplar(instance="new Foo() {intAryField=[a:1,2,3], strField=MyUtils.getATestString()}")
pulic void fooMethod()

@Exemplar(instance="Foo/1 {intAryField=[a:1,2,3], strField=MyUtils.getATestString()}")
pulic void fooMethod()

@Exemplar(instance="Foo/1! {intAryField=[a:1,2,3], strField=MyUtils.getATestString()}")
pulic void fooMethod()

@Exemplar(instance="Foo/1!" before="this {intAryField=[a:1,2,3], strField=MyUtils.getATestString()}")
public void fooMethod()

Previous Page   |   Next Page   |   Table of Contents

Comments are closed.