public class UnitTestModule extends AbstractScriptModule implements IScriptFunctionModifier
RESULT_NAME| Constructor and Description |
|---|
UnitTestModule() |
| Modifier and Type | Method and Description |
|---|---|
void |
addMetaData(java.lang.String name,
java.lang.Object value)
Append generic data to the current test, testfile or test suite.
|
ITestContainer |
addTestClass(java.lang.String className) |
static IAssertion |
assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.lang.Object errorDescription)
Expect two objects to be equal.
|
static IAssertion |
assertFalse(java.lang.Boolean actual,
java.lang.Object errorDescription)
Asserts when provided value is
true. |
void |
assertion(IAssertion reason)
Create a new assertion for the current test.
|
static IAssertion |
assertMatch(java.lang.String pattern,
java.lang.String candidate,
java.lang.String errorMessage)
Asserts when provided value does not match to a given regular expression pattern.
|
static IAssertion |
assertNotEquals(java.lang.Object expected,
java.lang.Object actual,
java.lang.Object errorDescription)
Expect two objects not to be equal.
|
static IAssertion |
assertNotNull(java.lang.Object actual,
java.lang.Object errorDescription)
Asserts when provided value is
null. |
static IAssertion |
assertNull(java.lang.Object actual,
java.lang.Object errorDescription)
Asserts when provided value is not
null. |
static IAssertion |
assertTrue(java.lang.Boolean actual,
java.lang.Object errorDescription)
Asserts when provided value is
false. |
void |
createReport(java.lang.String reportType,
ITestEntity suite,
java.lang.Object fileLocation,
java.lang.String title,
java.lang.String description)
Create a test report file.
|
void |
endTest()
End the current test.
|
void |
error(java.lang.String message)
Force an error for the current test entity (test/testclass/testfile/testsuite).
|
void |
error(java.lang.String message,
ScriptStackTrace stackTrace)
Called from the javascript runner.
|
java.lang.Object |
executeUserCode(java.lang.String location)
Execute code registered in the testsuite.
|
void |
failure(java.lang.String message)
Force a failure (=assertion) for the current test entity (test/testclass/testfile/testsuite).
|
void |
failure(java.lang.String message,
ScriptStackTrace stackTrace)
Called from the javascript runner.
|
java.lang.String |
getPostExecutionCode(java.lang.reflect.Method method)
Get code that shall be executed after actual method gets called.
|
java.lang.String |
getPreExecutionCode(java.lang.reflect.Method method)
Get code that shall be executed before actual method gets called.
|
static java.lang.String[] |
getReportTypes()
Get a list of available test report types.
|
ITest |
getTest()
Get the current unit test.
|
ITestFile |
getTestFile()
Get the currently executed test file instance.
|
ITestSuite |
getTestSuite()
Get the current test suite.
|
void |
ignoreTest(java.lang.String reason)
Ignore the current test.
|
ITestSuiteDefinition |
loadTestSuiteDefinition(java.lang.Object location)
Load a test suite definition from a given resource.
|
void |
saveTestSuiteDefinition(ITestSuiteDefinition testsuite,
java.lang.Object fileLocation)
Save a test suite definition to a file.
|
void |
setTestFile(ITestFile testFile)
Only to be called from Py4J engine to link this module to the current testfile.
|
void |
setTestSuite(ITestSuite testSuite)
Only to be called from Py4J engine to link this module to the current testsuite.
|
void |
setTestTimeout(long timeout)
Set the timeout for the current test.
|
void |
setThrowOnFailure(boolean throwOnFailure)
Changes behavior for assertion handling.
|
void |
startTest(java.lang.String title,
java.lang.String description)
Start a specific unit test.
|
getScriptEngine, initializepublic final void startTest(java.lang.String title,
@ScriptParameter(defaultValue="")
java.lang.String description)
endTest().title - name of testdescription - short test descriptionpublic final void endTest()
public ITestSuite getTestSuite()
public void setTestSuite(ITestSuite testSuite)
testSuite - testsuite to be setpublic ITestFile getTestFile()
public void setTestFile(ITestFile testFile)
testFile - testfile to be setpublic void addMetaData(java.lang.String name,
java.lang.Object value)
name - key to use. Has to be unique for this test objectvalue - data to be storedpublic static IAssertion assertEquals(java.lang.Object expected, java.lang.Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
expected - expected resultactual - actual resulterrorDescription - optional error text to be displayed when not equalpublic static IAssertion assertMatch(java.lang.String pattern, java.lang.String candidate, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String errorMessage)
pattern - pattern to matchcandidate - text to be matchederrorMessage - error message in case of a mismatchactual valuepublic static IAssertion assertNotEquals(java.lang.Object expected, java.lang.Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
expected - unexpected resultactual - actual resulterrorDescription - optional error text to be displayed when equalpublic static IAssertion assertNull(java.lang.Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
null.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertNotNull(java.lang.Object actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
null.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertTrue(java.lang.Boolean actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
false.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic static IAssertion assertFalse(java.lang.Boolean actual, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object errorDescription)
true.actual - value to verifyerrorDescription - optional error descriptionactual valuepublic void setThrowOnFailure(boolean throwOnFailure)
throwOnFailure - true to thow exceptions on assertionspublic java.lang.String getPreExecutionCode(java.lang.reflect.Method method)
IScriptFunctionModifiergetPreExecutionCode in interface IScriptFunctionModifiermethod - method that will be called afterwards.public java.lang.String getPostExecutionCode(java.lang.reflect.Method method)
IScriptFunctionModifiergetPostExecutionCode in interface IScriptFunctionModifiermethod - method that will be called before.public final void assertion(IAssertion reason) throws AssertionException
reason - assertion to be checkedAssertionException - in case setThrowOnFailure(boolean) is enabledpublic ITestContainer addTestClass(java.lang.String className)
public void ignoreTest(@ScriptParameter(defaultValue="") java.lang.String reason)
reason - message why the test got ignored.public void failure(java.lang.String message)
message - failure messagepublic void failure(java.lang.String message,
ScriptStackTrace stackTrace)
message - failure messagestackTrace - stacktrace of failure eventpublic ITest getTest()
public void error(java.lang.String message)
throws AssertionException
message - error messageAssertionException - containing the provided messagepublic void error(java.lang.String message,
ScriptStackTrace stackTrace)
message - error messagestackTrace - stacktrace of error eventpublic void setTestTimeout(long timeout)
timeout - timeout in [ms]public java.lang.Object executeUserCode(java.lang.String location)
throws java.lang.Exception
location - name of the code fragment to execute.java.lang.Exception - when no user specific code can be found or the injected code throwspublic static java.lang.String[] getReportTypes()
public void createReport(java.lang.String reportType,
ITestEntity suite,
java.lang.Object fileLocation,
java.lang.String title,
java.lang.String description)
throws java.io.IOException,
CoreException
reportType - type of report; see getReportTypes() for valuessuite - ITestEntity to be reportedfileLocation - location where report should be storedtitle - report titledescription - report description (ignored by some reports)CoreException - when we could not write to a workspace filejava.io.IOException - when we could not write to the file systempublic ITestSuiteDefinition loadTestSuiteDefinition(java.lang.Object location) throws java.io.IOException
location - location to load fromjava.io.IOException - when reading of definition failspublic void saveTestSuiteDefinition(ITestSuiteDefinition testsuite, java.lang.Object fileLocation) throws java.io.IOException, CoreException
testsuite - definition to savefileLocation - location to save file to (file system or workspace)CoreException - when we could not write to a workspace filejava.io.IOException - when we could not write to the file system