Package eu.simuline.testhelpers
Class TestCase
- java.lang.Object
-
- eu.simuline.testhelpers.TestCase
-
class TestCase extends java.lang.ObjectRepresents a test which may be a singular case or a suite during its lifetime from being scheduled to having runned successfully or not. In this respect, the testcase goes beyond aDescription. It is a wrapper around aDescriptiondescbut includes also the phase given by the qualityqual. If the test is a suite, the sub-tests are stored inchildren. Each test has an indexidxTestwhich identifies the test.Singular tests may be either
Quality.Scheduled,Quality.Startedor finished in some sense. If finished, the test may beQuality.Successor it has been interrupted by an exception wrapped in afailure. Also a timestamptimeis provided which indicates the running time of a singular test if it has been started and finished.This class provides a single non-private constructor transforming a description of a test which may be singular or a suite into a hierarchy of
TestCases.The methods are either
-
getter methods and their convenience methods like
getDesc(),isTest(),testCount(),getChildren(),getIdx(),getQuality(),hasFailed(),getThrown()andgetTime(). -
The special method
fullSuccess()indicating whether this testcase including all testcases succeeded. -
methods triggering phase transitions like
setScheduledRec(),setQualStartedIgnored(Quality),setFailure(Failure),setAssumptionFailure(Failure)andsetFinished()tied to events given byRunNotifier.
- Version:
- 1.0
- Author:
- Ernst Reissner
- See Also:
Created: Wed Jun 12 16:41:14 2006
-
getter methods and their convenience methods like
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<TestCase>childrenThe list of children if this is a suite according toisTest()ornullif this is a (singular) test.private DescriptiondescThe description of this testcase.private FailurefailureThe failure if any; otherwisenull.private intidxTestThe index of this testcase if this is a (singular) test; otherwise-1.private QualityqualThe phase of this testcase.private longtimeIf this testcase is a single testcase which has been finished, this is the span of time required to run this test.(package private) static longTIME_SCHEDULEDprivate static longTIME_SUITE
-
Constructor Summary
Constructors Modifier Constructor Description (package private)TestCase(Description desc)Creates a new testcase based on the descriptiondescwith indices0...n-1, wherenis the testcout ofdesc.privateTestCase(Description desc, int idxTest)Creates a new testcase based on the descriptiondescwith indicesidxTest...idxTest+n-1, wherenis the testcout ofdesc.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanfullSuccess()Returns whether this test including all sub-tests succeeded.(package private) java.util.List<TestCase>getChildren()Returns the list of children given bychildren.(package private) DescriptiongetDesc()Returns the description of this testcase given bydesc.(package private) intgetIdx()Returns the index of this testcase as described inidxTest.(package private) QualitygetQuality()Returns the phase of this testcase as described inqual.(package private) java.lang.ThrowablegetThrown()Returnsnullif no failure occurred.(package private) longgetTime()If this testcase is a single testcase which has been finished, this is the span of time required to run this test.(package private) booleanhasFailed()Returns whethergetThrown()returns non-null.(package private) booleanisTest()Returns whether this testcase is a (singular) test.(package private) voidsetAssumptionFailure(Failure failure)Triggers a transition of the current phase if the assumption failurefailureoccurs.(package private) voidsetFailure(Failure failure)Triggers a transition of the current phase if the non-assumption failurefailureoccurs.(package private) voidsetFinished()Triggers a transition of the current phase given by finishing the run of a singular testcase if possible as specified byQuality.setFinished().(package private) voidsetQualStartedIgnored(Quality qual)Triggers a transition of the current phase toqualif possible; otherwise throws an exception.(package private) voidsetScheduledRec()Recursively triggers a transition of the current phase toQuality.Scheduled: If this is a test, just setqualtoQuality.Scheduledif possible updatingfailureandtime.(package private) inttestCount()Returns the number of singular test in this testcase.java.lang.StringtoString()
-
-
-
Field Detail
-
desc
private final Description desc
The description of this testcase. This may be singular or not.
-
children
private final java.util.List<TestCase> children
The list of children if this is a suite according toisTest()ornullif this is a (singular) test.
-
idxTest
private final int idxTest
The index of this testcase if this is a (singular) test; otherwise-1. Each testcase is part of a tree hierarchy in which the singular tests have indices0...n-1if there arensingular test.
-
qual
private Quality qual
The phase of this testcase. The phase isnulliff this testcase is a suite. Otherwise, If this test is singular and newly created, the quality isQuality.Scheduled. State transitions are reigned byQuality.
-
failure
private Failure failure
The failure if any; otherwisenull. This isnulliff-
this is a test suite according to
isTest()and thusqualisnull. -
this is a singular test
(thus the phase
qualis non-null) and a failure is associated with the phase according toQuality.hasFailure().
-
this is a test suite according to
-
TIME_SUITE
private static final long TIME_SUITE
- See Also:
- Constant Field Values
-
TIME_SCHEDULED
static final long TIME_SCHEDULED
- See Also:
- Constant Field Values
-
time
private long time
If this testcase is a single testcase which has been finished, this is the span of time required to run this test. For single ignored tests, this is0and in the other cases, the value is negative. If this testcase is a suite, the result isTIME_SUITE; otherwise if scheduled it isTIME_SCHEDULED, both negative.- See Also:
Quality.setTime(long)
-
-
Constructor Detail
-
TestCase
TestCase(Description desc)
Creates a new testcase based on the descriptiondescwith indices0...n-1, wherenis the testcout ofdesc. This testcase is the root of a hierarchy of tests which consists of a single test ifdescis singular.All singular tests have quality
Quality.Scheduled.- Parameters:
desc- a description of this testcase. This may be singular or a test suite.
-
TestCase
private TestCase(Description desc, int idxTest)
Creates a new testcase based on the descriptiondescwith indicesidxTest...idxTest+n-1, wherenis the testcout ofdesc. This testcase is the root of a hierarchy of tests which consists of a single test ifdescis singular.All singular tests have quality
Quality.Scheduled.- Parameters:
desc- a description of this testcase. This may be singular or a test suite.idxTest- the minimal index of the (singular) tests to be created. To create the root of
-
-
Method Detail
-
getDesc
Description getDesc()
Returns the description of this testcase given bydesc. This may be singular or not.- Returns:
desc.
-
isTest
boolean isTest()
Returns whether this testcase is a (singular) test. Otherwise it is a testsuite. This is a frequently used convenience method.- Returns:
- this testcase is a (singular) test.
- See Also:
Description.isTest()
-
testCount
int testCount()
Returns the number of singular test in this testcase. This is1iff this is a singular test according toisTest(). This is a convenience method used once.- Returns:
- the number of singular test in this testcase.
- See Also:
Description.testCount()
-
getChildren
java.util.List<TestCase> getChildren()
Returns the list of children given bychildren.- Returns:
nullif this is a test suite according toisTest().- the list of children of this suite otherwise.
-
getQuality
Quality getQuality()
Returns the phase of this testcase as described inqual.- Returns:
qual
-
hasFailed
boolean hasFailed()
Returns whethergetThrown()returns non-null. For singular tests, returns the same value asQuality.hasFailure()applied toqual. This is a convenience method.- Returns:
- whether
getThrown()returns non-null. - See Also:
getThrown()
-
getThrown
java.lang.Throwable getThrown()
Returnsnullif no failure occurred. It returns non-nulliffqualisQuality.Error,Quality.FailureorQuality.Invalidated. In particular, it returnsnullifqualisnull.- Returns:
- the throwable defined by
failureif this is non-null, otherwise the throwable defined byFailure.getException(). - See Also:
Failure.getException()
-
getTime
long getTime()
If this testcase is a single testcase which has been finished, this is the span of time required to run this test. For single ignored tests, this is0and in the other cases, the value is negative. If this testcase is a suite, the result is-3.- Returns:
time- See Also:
Quality.setTime(long)
-
fullSuccess
boolean fullSuccess()
Returns whether this test including all sub-tests succeeded.- Returns:
- whether this test including all sub-tests succeeded.
-
setScheduledRec
void setScheduledRec()
Recursively triggers a transition of the current phase toQuality.Scheduled: If this is a test, just setqualtoQuality.Scheduledif possible updatingfailureandtime. If this is a suite, go recursively into thechildren.- Throws:
java.lang.IllegalStateException- if it is not allowed to set the phase toQuality.Scheduledaccording toQuality.setScheduled().
-
setQualStartedIgnored
void setQualStartedIgnored(Quality qual)
Triggers a transition of the current phase toqualif possible; otherwise throws an exception.- Parameters:
qual- eitherQuality.StartedorQuality.Ignored.- Throws:
java.lang.IllegalStateException--
if
qualis neitherQuality.StartednorQuality.Ignoredand in particular if it isnull. -
if
qualdoes not allow the transition toqual.
-
if
java.lang.NullPointerException- if this is a test suite and thusqualisnull.
-
setFailure
void setFailure(Failure failure)
Triggers a transition of the current phase if the non-assumption failurefailureoccurs. This presupposes that this is a singular test and that the current phase isQuality.Started. The new phase is eitherQuality.FailureorQuality.Errordepending on whether the thrown throwable is anAssertionError(should beAssertionFailedError).- Parameters:
failure- a failure representing either a proper failure or an error but not an assumption failure.- Throws:
java.lang.IllegalStateException- iffailurerepresents anAssumptionViolatedExceptionviaFailure.getException().java.lang.IllegalStateException- iffailuredoes not represent anAssumptionViolatedException, this is a singular test andqualdoes not allow the transition given by a failurefailure, i.e.qualis notQuality.Started.java.lang.NullPointerException- iffailuredoes not represent anAssumptionViolatedExceptionand this is a test suite and thusqualisnull.- See Also:
setAssumptionFailure(Failure),Quality.setFailure(Throwable)
-
setAssumptionFailure
void setAssumptionFailure(Failure failure)
Triggers a transition of the current phase if the assumption failurefailureoccurs. This presupposes that this is a singular test and that the current phase isQuality.Started. The new phase isQuality.Invalidated.- Parameters:
failure- a failure representing a failed assumption.- Throws:
java.lang.IllegalStateException- iffailuredoes not represent anAssumptionViolatedExceptionviaFailure.getException().java.lang.IllegalStateException- iffailurerepresents anAssumptionViolatedException, this is a singlar test andqualdoes not allow the transition toQuality.Invalidated.java.lang.NullPointerException- iffailurerepresents anAssumptionViolatedExceptionand this is a test suite and thusqualisnull.- See Also:
setFailure(Failure)
-
setFinished
void setFinished()
Triggers a transition of the current phase given by finishing the run of a singular testcase if possible as specified byQuality.setFinished(). The new phase is- remains unchanged for phases
Quality.Failure,Quality.InvalidatedandQuality.Error Quality.Successfor current phaseQuality.Started.
timeto the time required to run this testcase.- Throws:
java.lang.IllegalStateException- if this is a singular test andqualdoes not allow the transition by finishing a test case. This is the case for statesQuality.Scheduled,Quality.SuccessandQuality.Ignored.java.lang.NullPointerException- if this is a test suite and thusqualisnull.- See Also:
setFailure(Failure)
- remains unchanged for phases
-
-