public class UnitTestModule extends AbstractScriptModule implements IScriptFunctionModifier
RESULT_NAME
Constructor and Description |
---|
UnitTestModule() |
Modifier and Type | Method and Description |
---|---|
void |
addMetaData(String name,
Object value)
Append generic data to the current test, testfile or test suite.
|
ITestContainer |
addTestClass(String className) |
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 |
assertMatch(String pattern,
String candidate,
String errorMessage)
Asserts when provided value does not match to a given regular expression pattern.
|
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 . |
void |
createReport(String reportType,
ITestEntity suite,
Object fileLocation,
String title,
String description)
Create a test report file.
|
void |
endTest()
End the current test.
|
void |
error(String message)
Force an error for the current test entity (test/testclass/testfile/testsuite).
|
void |
error(String message,
ScriptStackTrace stackTrace)
Called from the javascript runner.
|
Object |
executeUserCode(String location)
Execute code registered in the testsuite.
|
void |
failure(String message)
Force a failure (=assertion) for the current test entity (test/testclass/testfile/testsuite).
|
void |
failure(String message,
ScriptStackTrace stackTrace)
Called from the javascript runner.
|
ITest |
getCurrentTest()
Get the current unit test.
|
String |
getPostExecutionCode(Method method)
Get code that shall be executed after actual method gets called.
|
String |
getPreExecutionCode(Method method)
Get code that shall be executed before actual method gets called.
|
static String[] |
getReportTypes()
Get a list of available test report types.
|
ITestFile |
getTestFile()
Get the currently executed test file instance.
|
ITestSuite |
getTestSuite()
Get the current test suite.
|
void |
ignoreTest(String reason)
Ignore the current test.
|
ITestSuiteDefinition |
loadTestSuiteDefinition(Object location)
Load a test suite definition from a given resource.
|
void |
saveTestSuiteDefinition(ITestSuiteDefinition testsuite,
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(String title,
String description)
Start a specific unit test.
|
getScriptEngine, initialize
public final void startTest(String title, @ScriptParameter(defaultValue="") 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(String name, Object value)
name
- key to use. Has to be unique for this test objectvalue
- data to be storedpublic 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 assertMatch(String pattern, String candidate, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String errorMessage)
pattern
- pattern to matchcandidate
- text to be matchederrorMessage
- error message in case of a mismatchactual
valuepublic 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 setThrowOnFailure(boolean throwOnFailure)
throwOnFailure
- true
to thow exceptions on assertionspublic String getPreExecutionCode(Method method)
IScriptFunctionModifier
getPreExecutionCode
in interface IScriptFunctionModifier
method
- method that will be called afterwards.public String getPostExecutionCode(Method method)
IScriptFunctionModifier
getPostExecutionCode
in interface IScriptFunctionModifier
method
- 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(String className)
public void ignoreTest(@ScriptParameter(defaultValue="") String reason)
reason
- message why the test got ignored.public void failure(String message)
message
- failure messagepublic void failure(String message, ScriptStackTrace stackTrace)
message
- failure messagestackTrace
- stacktrace of failure eventpublic ITest getCurrentTest()
public void error(String message) throws Exception
message
- error messageException
public void error(String message, ScriptStackTrace stackTrace)
message
- error messagestackTrace
- stacktrace of error eventpublic void setTestTimeout(long timeout)
timeout
- timeout in [ms]public Object executeUserCode(String location) throws Exception
location
- name of the code fragment to execute.Exception
- when no user specific code can be found or the injected code throwspublic static String[] getReportTypes()
public void createReport(String reportType, ITestEntity suite, Object fileLocation, String title, String description) throws 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 fileIOException
- when we could not write to the file systempublic ITestSuiteDefinition loadTestSuiteDefinition(Object location) throws IOException
location
- location to load fromIOException
- when reading of definition failspublic void saveTestSuiteDefinition(ITestSuiteDefinition testsuite, Object fileLocation) throws IOException, CoreException
testsuite
- definition to savefileLocation
- location to save file to (file system or workspace)CoreException
- when we could not write to a workspace fileIOException
- when we could not write to the file system