Class AbstractTest
java.lang.Object
org.apache.batik.test.AbstractTest
- All Implemented Interfaces:
Test
- Direct Known Subclasses:
AbstractRenderingAccuracyTest, DefaultTestSuite, DummyValidTest, ImageCompareTest, ParametrizedTest, PerformanceTest, PerformanceTestValidator, SelfContainedSVGOnLoadTest, SelfContainedSVGOnLoadTestValidator.DefaultErrorTest, SelfContainedSVGOnLoadTestValidator.ReportSuccess, SVGOnLoadExceptionTest, SVGRenderingAccuracyTestValidator.DefaultConfigTest, TestReportValidator, XMLTestSuiteRunnerValidator.XMLTestSuiteRunnerTest
Base class containing convenience methods for writing tests.
There are at least three approaches to write new tests derived from
There are at least three approaches to write new tests derived from
AbstractTest:- You can simply override the
runImplBasicmethod and return true or false depending on whether or not the test fails. - You can choose to report more complex test failure conditions
by overriding the
runImplmethod which returns aTestReport. In that case, you can use the convenience methods such asreportFailurereportSuccessorreportExceptionto help build aTestReport, and use theTestReport'saddDescriptionEntryto populate the report with relevant error description. - You can choose to use the various assertion methods such as
assertNull,assertEqualsorassertTrue. These methods throw exceptions which will be turned inTestReportsby theAbstractTest.
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();
}
- Version:
- $Id$
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertEquals(int ref, int cmp) voidassertEquals(Object ref, Object cmp) Convenience method to check for a specific condition.voidassertNull(Object ref) Convenience method to check that a reference is nullvoidassertTrue(boolean b) Convenience method to check that a given boolean is true.voidConvenience method to report an error condition.getId()Return thisTest's id.getName()Returns thisTest's name.Returns thisTest's parent, in case thisTestis part of aTestSuite.Return thisTest's qualified id.reportError(String errorCode) Convenience method to report a simple error code.reportException(String errorCode, Exception e) Convenience method to help implementations report errors.Convenience method.run()This default implementation of the run method catches any Exception thrown from the runImpl method and creates aTestReportindicating an internalTestfailure when that happens.runImpl()Subclasses should implement this method with the content of the test case.booleanIn the simplest test implementation, developers can simply implement the following method.voidSet thisTest's id.voidSets this test's namevoidSet thisTest's parent.
-
Field Details
-
id
This test's id. -
parent
This test's parent, in case this test is part of a suite. -
name
This test's name. If null, the class' name is returned. -
report
TestReport
-
-
Constructor Details
-
AbstractTest
public AbstractTest()
-
-
Method Details
-
getName
-
setName
Sets this test's name -
getId
-
getQualifiedId
Return thisTest's qualified id.- Specified by:
getQualifiedIdin interfaceTest
-
setId
-
getParent
-
setParent
-
run
This default implementation of the run method catches any Exception thrown from the runImpl method and creates aTestReportindicating an internalTestfailure when that happens. Otherwise, this method simply returns theTestReportgenerated by therunImplmethod. -
runImpl
Subclasses should implement this method with the content of the test case. Typically, implementations will choose to catch and process all exceptions and error conditions they are looking for in the code they exercise but will let exceptions due to their own processing propagate.- Throws:
Exception
-
runImplBasic
-
reportSuccess
Convenience method. -
reportError
Convenience method to report a simple error code. -
error
Convenience method to report an error condition.- Throws:
TestErrorConditionException
-
assertNull
Convenience method to check that a reference is null- Throws:
AssertNullException
-
assertTrue
Convenience method to check that a given boolean is true.- Throws:
AssertTrueException
-
assertEquals
Convenience method to check for a specific condition. Returns true if both objects are null or if ref is not null and ref.equals(cmp) is true.- Throws:
AssertEqualsException
-
assertEquals
- Throws:
AssertEqualsException
-
reportException
Convenience method to help implementations report errors. AnAbstractTestextension 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"
Note that the implementor will also need to add an entry in its Messages.properties file. That file is expected to be in a resource file calledMessageshaving the same package name as theTestclass, appended with ".resources".
-