Unittest Module

Library providing UnitTest functionality. Unit tests are parts of a JavaScript file which are embedded between a startTest() and an endTest() function call. Every function result returned inbetween will be checked for a response of type IAssertion. If such a response is detected its result will automatically be applied to the current unit test.

Dependencies

This module depends on following other modules which will automatically be loaded.

Method Overview

Method Description
addMetaData() Add metadata to the current test object.
assertEquals() Expect two objects to be equal.
assertFalse() Asserts when provided value is true.
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.
disableAssertions() Disables automatic assertions in tests.
enableAssertions() Enables automatic assertions in tests.
endTest() End the current test.
error() Add a new error to the current testcase.
executeUserCode() Insert additional test code at a given code location.
failure() Report a new failure for the current UnitTest.
getReportTypes() Get a list of available report types.
getTest() Get a Test instance.
getTestFile() Get the current TestFile instance.
getTestSuite() Get the current TestSuite instance.
getVariable() Get the content of the variable by its identifier.
getVariables() Array of available variables.
ignoreAssertions() Define amount of upcoming assertions to be ignored.
openTestSuite() Open a testsuite without executing it.
removeVariable() Remove the variable with the given identifier.
runUnitTest() Run a unit test.
setVariable() Set the content of a variable defined by its identifier.
startTest() Start a specific unit test.
waitForCompletion() Wait until a test entity is completed.

Methods

addMetaData

void addMetaData(java.lang.String key, java.lang.String data)

Add metadata to the current test object. Metadata is stored as a Map, so setting with an already existing keyword will override the previous setting.

Parameter Type Description
key java.lang.String metadata keyword
data java.lang.String metadata

assertEquals

org.eclipse.ease.modules.unittest.modules.IAssertion assertEquals(java.lang.Object expected, java.lang.Object actual, [java.lang.Object errorDescription])

Expect two objects to be equal.

Parameter Type Description
expected java.lang.Object expected result
actual java.lang.Object actual result
errorDescription java.lang.Object optional error text to be displayed when not equal
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion containing comparison result

assertFalse

org.eclipse.ease.modules.unittest.modules.IAssertion assertFalse(boolean actual, [java.lang.Object errorDescription])

Asserts when provided value is true.

Parameter Type Description
actual boolean value to verify
errorDescription java.lang.Object optional error description
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion depending on actual value

assertNotEquals

org.eclipse.ease.modules.unittest.modules.IAssertion assertNotEquals(java.lang.Object expected, java.lang.Object actual, [java.lang.Object errorDescription])

Expect two objects not to be equal.

Parameter Type Description
expected java.lang.Object unexpected result
actual java.lang.Object actual result
errorDescription java.lang.Object optional error text to be displayed when equal
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion containing comparison result

assertNotNull

org.eclipse.ease.modules.unittest.modules.IAssertion assertNotNull(java.lang.Object actual, [java.lang.Object errorDescription])

Asserts when provided value is null.

Parameter Type Description
actual java.lang.Object value to verify
errorDescription java.lang.Object optional error description
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion depending on actual value

assertNull

org.eclipse.ease.modules.unittest.modules.IAssertion assertNull(java.lang.Object actual, [java.lang.Object errorDescription])

Asserts when provided value is not null.

Parameter Type Description
actual java.lang.Object value to verify
errorDescription java.lang.Object optional error description
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion depending on actual value

assertTrue

org.eclipse.ease.modules.unittest.modules.IAssertion assertTrue(boolean actual, [java.lang.Object errorDescription])

Asserts when provided value is false.

Parameter Type Description
actual boolean value to verify
errorDescription java.lang.Object optional error description
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.modules.IAssertion ... assertion depending on actual value

assertion

void assertion(org.eclipse.ease.modules.unittest.modules.IAssertion reason)

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

Parameter Type Description
reason org.eclipse.ease.modules.unittest.modules.IAssertion assertion to be checked

createReport

boolean createReport(java.lang.String reportType, org.eclipse.ease.modules.unittest.components.TestSuite suite, java.lang.String fileLocation, java.lang.String title, java.lang.String description)

Create a test report file.

Parameter Type Description
reportType java.lang.String type of report; see getReportTypes() for values
suite org.eclipse.ease.modules.unittest.components.TestSuite TestSuite to be reported
fileLocation java.lang.String location where report should be stored
title java.lang.String report title
description java.lang.String report description (ignored by some reports)

Returns:boolean ... true when report was created successfully

disableAssertions

void disableAssertions()

Disables automatic assertions in tests. When set user generated errors, warnings, failures will still be reported, but assert functions will not report errors. Assertions are automatically enabled on a startTest(String, String) command.

enableAssertions

void enableAssertions()

Enables automatic assertions in tests. This is the default setting for any testfile.

endTest

void endTest()

End the current test.

error

void error(java.lang.String message)

Add a new error to the current testcase.

Parameter Type Description
message java.lang.String error message

executeUserCode

void executeUserCode(java.lang.String identifier)

Insert additional test code at a given code location. Some code locations are predefined like start test file or start test case. Others may be freely defined by the unit test execution target. Those other tests need to be invoked by the unit tests by calling executeUserCode(identifier);.

Parameter Type Description
identifier java.lang.String code identifier

failure

void failure(java.lang.String message)

Report a new failure for the current UnitTest.

Parameter Type Description
message java.lang.String failure message

getReportTypes

java.lang.String getReportTypes()

Get a list of available report types.

Returns:java.lang.String ... String array containing available report types

getTest

org.eclipse.ease.modules.unittest.components.Test getTest([java.lang.String name])

Get a Test instance. if no name is provided, the current test instance is returned. When provided, this method searches for a test with the given title.

Parameter Type Description
name java.lang.String test name to look for
Optional: defaults to <null>.

Returns:org.eclipse.ease.modules.unittest.components.Test ... current test or null

getTestFile

org.eclipse.ease.modules.unittest.components.TestFile getTestFile()

Get the current TestFile instance.

Returns:org.eclipse.ease.modules.unittest.components.TestFile ... test file instance

getTestSuite

org.eclipse.ease.modules.unittest.components.TestSuite getTestSuite()

Get the current TestSuite instance.

Returns:org.eclipse.ease.modules.unittest.components.TestSuite ... test suite instance

getVariable

org.eclipse.ease.modules.unittest.components.TestSuiteModel.Variable getVariable(org.eclipse.ease.modules.unittest.components.TestSuite testSuite, java.lang.String identifier)

Get the content of the variable by its identifier. If the variable does not exist null is returned.

Parameter Type Description
testSuite org.eclipse.ease.modules.unittest.components.TestSuite opened TestSuite
identifier java.lang.String unique identifier

Returns:org.eclipse.ease.modules.unittest.components.TestSuiteModel.Variable ... the variable or null

getVariables

org.eclipse.ease.modules.unittest.components.TestSuiteModel.Variable getVariables(org.eclipse.ease.modules.unittest.components.TestSuite testSuite)

Array of available variables.

Parameter Type Description
testSuite org.eclipse.ease.modules.unittest.components.TestSuite opened TestSuite

Returns:org.eclipse.ease.modules.unittest.components.TestSuiteModel.Variable ... array of available variables

ignoreAssertions

void ignoreAssertions(int count)

Define amount of upcoming assertions to be ignored. Allows to ignore count upcoming assertions (not depending on actual assertion status). Assertions are enabled again once the counter reaches 0,when enableAssertions() is called or a new test is started using startTest(String, String).

Parameter Type Description
count int assertions to be ignored

openTestSuite

org.eclipse.ease.modules.unittest.components.TestSuite openTestSuite(java.lang.String filename)

Open a testsuite without executing it.

Parameter Type Description
filename java.lang.String location of testsuite file. Must be a file from the workspace

Returns:org.eclipse.ease.modules.unittest.components.TestSuite ... TestSuite definition or null

removeVariable

void removeVariable(org.eclipse.ease.modules.unittest.components.TestSuite testSuite, java.lang.String identifier)

Remove the variable with the given identifier. After the variable is removed it will not be available during the TestSuite execution.

Parameter Type Description
testSuite org.eclipse.ease.modules.unittest.components.TestSuite opened TestSuite
identifier java.lang.String unique identifier of the variable

runUnitTest

org.eclipse.ease.modules.unittest.components.TestSuite runUnitTest(java.lang.Object executable)

Run a unit test. If the file addressed is a suite, then the whole suite is started. If the file is a simple JavaScript file, then a dynamic suite is created that contains just the one file.

Parameter Type Description
executable java.lang.Object

Returns:org.eclipse.ease.modules.unittest.components.TestSuite ... TestSuite definition or null

setVariable

void setVariable(org.eclipse.ease.modules.unittest.components.TestSuite testSuite, java.lang.String identifier, java.lang.String content, [java.lang.String description], [java.lang.String path])

Set the content of a variable defined by its identifier. If the variable with the given identifier does not exist a new one is created.

Parameter Type Description
testSuite org.eclipse.ease.modules.unittest.components.TestSuite opened TestSuite
identifier java.lang.String unique identifier
content java.lang.String
description java.lang.String
Optional: defaults to <null>.
path java.lang.String path of the variable
Optional: defaults to <null>.

startTest

void startTest(java.lang.String title, [java.lang.String description])

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

Parameter Type Description
title java.lang.String name of test
description java.lang.String short test description
Optional: defaults to <"">.

waitForCompletion

boolean waitForCompletion(org.eclipse.ease.modules.unittest.components.TestComposite testObject)

Wait until a test entity is completed. If the entity is not scheduled this method might stall forever!

Parameter Type Description
testObject org.eclipse.ease.modules.unittest.components.TestComposite TestSuite or Test to wait for

Returns:boolean ... true on success, false if test was interrupted