Unittest Module

Support methods for scripted unit tests. Provides several assertion methods and utility functions to manipulate the current test instances and states.

Method Overview

Method Description
addMetaData() Append generic data to the current test, testfile or test suite.
assertEquals() Expect two objects to be equal.
assertFalse() Asserts when provided value is true.
assertMatch() Asserts when provided value does not match to a given regular expression pattern.
assertNotEquals() Expect two objects not to be equal.
assertNotNull() Asserts when provided value is null.
assertNull() Asserts when provided value is not null.
assertTrue() Asserts when provided value is false.
assertion() Create a new assertion for the current test.
createReport() Create a test report file.
endTest() End the current test.
error() Force an error for the current test entity (test/testclass/testfile/testsuite).
executeUserCode() Execute code registered in the testsuite.
failure() Force a failure (=assertion) for the current test entity (test/testclass/testfile/testsuite).
getReportTypes() Get a list of available test report types.
getTest() Get the current unit test.
getTestFile() Get the currently executed test file instance.
getTestSuite() Get the current test suite.
ignore() Ignore the current test, the current testfile or test suite.
ignoreTest() Alias for ignore().
loadTestSuiteDefinition() Load a test suite definition from a given resource.
saveTestSuiteDefinition() Save a test suite definition to a file.
setTestTimeout() Set the timeout for the current test.
startTest() Start a specific unit test.

Methods

addMetaData

void addMetaData(String name, Object value)

Append generic data to the current test, testfile or test suite.

name
key to use. Has to be unique for this test object
value
data to be stored

assertEquals

IAssertion assertEquals(Object expected, Object actual, [Object errorDescription])

Expect two objects to be equal.

expected
expected result
actual
actual result
errorDescription
optional error text to be displayed when not equalOptional: defaults to <null>.

assertion containing comparison result

assertFalse

IAssertion assertFalse(Boolean actual, [Object errorDescription])

Asserts when provided value is true.

actual
value to verify
errorDescription
optional error descriptionOptional: defaults to <null>.

assertion depending on actual value

assertMatch

IAssertion assertMatch(String pattern, String candidate, [String errorMessage])

Asserts when provided value does not match to a given regular expression pattern.

pattern
pattern to match
candidate
text to be matched
errorMessage
error message in case of a mismatchOptional: defaults to <null>.

assertion depending on actual value

assertNotEquals

IAssertion assertNotEquals(Object expected, Object actual, [Object errorDescription])

Expect two objects not to be equal.

expected
unexpected result
actual
actual result
errorDescription
optional error text to be displayed when equalOptional: defaults to <null>.

assertion containing comparison result

assertNotNull

IAssertion assertNotNull(Object actual, [Object errorDescription])

Asserts when provided value is null.

actual
value to verify
errorDescription
optional error descriptionOptional: defaults to <null>.

assertion depending on actual value

assertNull

IAssertion assertNull(Object actual, [Object errorDescription])

Asserts when provided value is not null.

actual
value to verify
errorDescription
optional error descriptionOptional: defaults to <null>.

assertion depending on actual value

assertTrue

IAssertion assertTrue(Boolean actual, [Object errorDescription])

Asserts when provided value is false.

actual
value to verify
errorDescription
optional error descriptionOptional: defaults to <null>.

assertion depending on actual value

assertion

void assertion(IAssertion reason) throws AssertionException

Create a new assertion for the current test. According to the assertion status an error might be added to the current testcase.

reason
assertion to be checked
AssertionException
in case setThrowOnFailure() is enabled

createReport

void createReport(String reportType, ITestEntity suite, Object fileLocation, [String title], [String description], [Object reportData]) throws IOException, CoreException

Create a test report file.

reportType
type of report; see getReportTypes() for values
suite
ITestEntity to be reported
fileLocation
location where report should be stored
title
report titleOptional: defaults to <Test Report>.
description
report description (ignored by some reports)Optional: defaults to <>.
reportData
additional report data. Specific to report typeOptional: defaults to <null>.
IOException
when we could not write to the file system
CoreException
when we could not write to a workspace file

endTest

void endTest()

End the current test. Does nothing if no test was started.

error

void error(String message) throws AssertionException

Force an error for the current test entity (test/testclass/testfile/testsuite).

message
error message
AssertionException
containing the provided message

executeUserCode

Object executeUserCode(String location) throws Exception

Execute code registered in the testsuite.

location
name of the code fragment to execute.

execution result

Exception
when no user specific code can be found or the injected code throws

failure

void failure(String message)

Force a failure (=assertion) for the current test entity (test/testclass/testfile/testsuite).

message
failure message

getReportTypes

String[] getReportTypes()

Get a list of available test report types.

String array containing available report types

getTest

ITest getTest()

Get the current unit test.

the current test or a generic global test scope if called outside of a valid testcase

getTestFile

ITestFile getTestFile()

Get the currently executed test file instance. The test file is not a file instance but the runtime representation of a testsuite test file.

test file instance

getTestSuite

ITestSuite getTestSuite()

Get the current test suite.

test suite instance

ignore

void ignore([String reason])

Ignore the current test, the current testfile or test suite. What is ignored depends on the scope this command is executed in.

Alias: ignoreTest()

reason
message why the test got ignored.Optional: defaults to <>.

loadTestSuiteDefinition

ITestSuiteDefinition loadTestSuiteDefinition(Object location) throws IOException

Load a test suite definition from a given resource.

location
location to load from

test suite definition

IOException
when reading of definition fails

saveTestSuiteDefinition

void saveTestSuiteDefinition(ITestSuiteDefinition testsuite, Object fileLocation) throws IOException, CoreException

Save a test suite definition to a file.

testsuite
definition to save
fileLocation
location to save file to (file system or workspace)
IOException
when we could not write to the file system
CoreException
when we could not write to a workspace file

setTestTimeout

void setTestTimeout(long timeout)

Set the timeout for the current test. If test execution takes longer than the timeout, the test is marked as failed.

timeout
timeout in [ms]

startTest

void startTest(String title, [String description])

Start a specific unit test. Started tests should be terminated by an {module #endTest()}.

title
name of test
description
short test descriptionOptional: defaults to <>.