public abstract class AbstractTest extends Object implements Test
AbstractTest:runImplBasic method and
return true or false depending on whether or not the test fails.runImpl method which returns a TestReport.
In that case, you can use the convenience methods such as reportFailure
reportSuccess or reportException to help build a TestReport,
and use the TestReport's addDescriptionEntry to populate
the report with relevant error description.assertNull,
assertEquals or assertTrue. These methods throw exceptions which
will be turned in TestReports by the AbstractTest.
public class MyTestA extends AbstractTest {
public boolean runImplBasic() {
if(someConditionFails){
return false;
}
return true;
}
}
public class MyTestB extends AbstractTest {
public TestReport runImpl() {
if(someConditionFails){
TestReport report = reportError(MY_ERROR_CODE);
report.addDescriptionEntry(ENTRY_KEY_MY_ERROR_DESCRIPTION_KEY,
myErrorDescriptionValue);
return report;
}
return reportSuccess();
}
public class MyTestC extends AbstractTest {
public TestReport runImpl() throws Exception {
assertTrue(somCondition);
assertEquals(valueA, valueB);
assertNull(shouldBeNullRef);
if(someErrorCondition){
error(MY_ERROR_CODE);
}
return reportSuccess();
}
| Modifier and Type | Field and Description |
|---|---|
protected String |
id
This test's id.
|
protected String |
name
This test's name.
|
protected TestSuite |
parent
This test's parent, in case this test is part of
a suite.
|
| Constructor and Description |
|---|
AbstractTest() |
| Modifier and Type | Method and Description |
|---|---|
void |
assertEquals(int ref,
int cmp) |
void |
assertEquals(Object ref,
Object cmp)
Convenience method to check for a specific condition.
|
void |
assertNull(Object ref)
Convenience method to check that a reference is null
|
void |
assertTrue(boolean b)
Convenience method to check that a given boolean is true.
|
void |
error(String errorCode)
Convenience method to report an error condition.
|
String |
getId()
Return this
Test's id. |
String |
getName()
Returns this
Test's name. |
TestSuite |
getParent()
Returns this
Test's parent, in case this
Test is part of a TestSuite. |
String |
getQualifiedId()
Return this
Test's qualified id. |
TestReport |
reportError(String errorCode)
Convenience method to report a simple error code.
|
TestReport |
reportException(String errorCode,
Exception e)
Convenience method to help implementations report errors.
|
TestReport |
reportSuccess()
Convenience method.
|
TestReport |
run()
This default implementation of the run method
catches any Exception thrown from the
runImpl method and creates a
TestReport
indicating an internal Test failure
when that happens. |
TestReport |
runImpl()
Subclasses should implement this method with the content of
the test case.
|
boolean |
runImplBasic()
In the simplest test implementation, developers can
simply implement the following method.
|
void |
setId(String id)
Set this
Test's id. |
void |
setName(String name)
Sets this test's name
|
void |
setParent(TestSuite parent)
Set this
Test's parent. |
protected String id
protected TestSuite parent
protected String name
public void setName(String name)
public String getQualifiedId()
Test's qualified id.getQualifiedId in interface Testpublic void setId(String id)
Test's id. Null is not allowed.public TestSuite getParent()
TestTest's parent, in case this
Test is part of a TestSuite.
The returned value may be null.public void setParent(TestSuite parent)
TestTest's parent.public TestReport run()
TestReport
indicating an internal Test failure
when that happens. Otherwise, this method
simply returns the TestReport generated
by the runImpl method.public TestReport runImpl() throws Exception
Exceptionpublic boolean runImplBasic()
throws Exception
Exceptionpublic TestReport reportSuccess()
public TestReport reportError(String errorCode)
public void error(String errorCode) throws TestErrorConditionException
TestErrorConditionExceptionpublic void assertNull(Object ref) throws AssertNullException
AssertNullExceptionpublic void assertTrue(boolean b)
throws AssertTrueException
AssertTrueExceptionpublic void assertEquals(Object ref, Object cmp) throws AssertEqualsException
AssertEqualsExceptionpublic void assertEquals(int ref,
int cmp)
throws AssertEqualsException
AssertEqualsExceptionpublic TestReport reportException(String errorCode, Exception e)
AbstractTest extension will typically catch
exceptions for specific error conditions it wants to point
out. For example:
public TestReport runImpl() throws Exception {
try{
.... something ....
catch(MySpecialException e){
return reportException(MY_SPECIAL_ERROR_CODE, e);
}
public static final String MY_SPECIAL_ERROR_CODE = "myNonQualifiedClassName.my.error.code"
Messages having the same package
name as the Test class, appended with ".resources".Copyright © 2000–2024 Apache Software Foundation. All rights reserved.