public class UnitTestModule extends AbstractScriptModule implements IScriptFunctionModifier
IAssertion. If such a response is detected its result will
automatically be applied to the current unit test.| Modifier and Type | Field and Description |
|---|---|
static String |
FAIL_ON_ERROR_VARIABLE |
static String |
INJECTED_MAIN |
static String |
MODULE_NAME |
RESULT_NAME| Constructor and Description |
|---|
UnitTestModule() |
| Modifier and Type | Method and Description |
|---|---|
void |
addMetaData(String key,
String data)
Add metadata to the current test object.
|
static IAssertion |
assertEquals(Object expected,
Object actual,
Object errorDescription)
Expect two objects to be equal.
|
static IAssertion |
assertFalse(boolean actual,
Object errorDescription)
Asserts when provided value is
true. |
void |
assertion(IAssertion reason)
Create a new assertion for the current test.
|
static IAssertion |
assertNotEquals(Object expected,
Object actual,
Object errorDescription)
Expect two objects not to be equal.
|
static IAssertion |
assertNotNull(Object actual,
Object errorDescription)
Asserts when provided value is
null. |
static IAssertion |
assertNull(Object actual,
Object errorDescription)
Asserts when provided value is not
null. |
static IAssertion |
assertTrue(boolean actual,
Object errorDescription)
Asserts when provided value is
false. |
boolean |
createReport(String reportType,
TestSuite suite,
String fileLocation,
String title,
String description)
Create a test report file.
|
void |
disableAssertions()
Disables automatic assertions in tests.
|
void |
enableAssertions()
Enables automatic assertions in tests.
|
void |
endTest()
End the current test.
|
void |
error(String message)
Add a new error to the current testcase.
|
void |
executeUserCode(String identifier)
Insert additional test code at a given code location.
|
void |
failure(String message)
Report a new failure for the current UnitTest.
|
String |
getPostExecutionCode(Method method) |
String |
getPreExecutionCode(Method method) |
static String[] |
getReportTypes()
Get a list of available report types.
|
Test |
getTest(String name)
Get a
Test instance. |
TestFile |
getTestFile()
Get the current
TestFile instance. |
TestSuite |
getTestSuite()
Get the current
TestSuite instance. |
void |
ignoreAssertions(int count)
Define amount of upcoming assertions to be ignored.
|
TestSuite |
openTestSuite(String filename)
Open a testsuite without executing it.
|
TestSuite |
runUnitTest(Object executable)
Run a unit test.
|
void |
startTest(String title,
String description)
Start a specific unit test.
|
static boolean |
waitForCompletion(TestComposite testObject)
Wait until a test entity is completed.
|
getScriptEngine, initializepublic static final String MODULE_NAME
public static final String INJECTED_MAIN
public static final String FAIL_ON_ERROR_VARIABLE
public TestSuite runUnitTest(Object executable)
filename - location of testsuite or testfile. Must be a file from the workspaceTestSuite definition or nullpublic TestSuite openTestSuite(String filename) throws IOException, CoreException
filename - location of testsuite file. Must be a file from the workspaceTestSuite definition or nullIOExceptionCoreExceptionpublic boolean createReport(String reportType, TestSuite suite, String fileLocation, String title, String description) throws Exception
reportType - type of report; see getReportTypes() for valuessuite - TestSuite to be reportedfileLocation - location where report should be storedtitle - report titledescription - report description (ignored by some reports)true when report was created successfullyException - thrown on file write errorspublic static String[] getReportTypes()
public String getPreExecutionCode(Method method)
getPreExecutionCode in interface IScriptFunctionModifierpublic String getPostExecutionCode(Method method)
getPostExecutionCode in interface IScriptFunctionModifierpublic final void startTest(String title, @ScriptParameter(defaultValue="") String description)
endTest().title - name of testdescription - short test descriptionpublic final void endTest()
public final void assertion(IAssertion reason)
reason - assertion to be checkedpublic final void error(String message)
message - error messagepublic final void failure(String message)
message - failure messagepublic TestFile getTestFile()
TestFile instance.public Test getTest(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String name)
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.name - test name to look fornullpublic TestSuite getTestSuite()
TestSuite instance.public final void executeUserCode(String identifier)
executeUserCode(identifier);.identifier - code identifierpublic static IAssertion assertEquals(Object expected, Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
expected - expected resultactual - actual resulterrorDescription - optional error text to be displayed when not equalpublic static IAssertion assertNotEquals(Object expected, Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
expected - unexpected resultactual - actual resulterrorDescription - optional error text to be displayed when equalpublic static IAssertion assertNull(Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
null.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertNotNull(Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
null.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertTrue(boolean actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
false.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertFalse(boolean actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object errorDescription)
true.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic void disableAssertions()
startTest(String, String) command.public void enableAssertions()
public void ignoreAssertions(int count)
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).count - assertions to be ignoredpublic static boolean waitForCompletion(TestComposite testObject)