Package eu.simuline.testhelpers
Class TestCase
- java.lang.Object
-
- eu.simuline.testhelpers.TestCase
-
class TestCase extends java.lang.Object
Represents 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 aDescription
desc
but includes also the phase given by the qualityqual
. If the test is a suite, the sub-tests are stored inchildren
. Each test has an indexidxTest
which identifies the test.Singular tests may be either
Quality.Scheduled
,Quality.Started
or finished in some sense. If finished, the test may beQuality.Success
or it has been interrupted by an exception wrapped in afailure
. Also a timestamptime
is 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
TestCase
s.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>
children
The list of children if this is a suite according toisTest()
ornull
if this is a (singular) test.private Description
desc
The description of this testcase.private Failure
failure
The failure if any; otherwisenull
.private int
idxTest
The index of this testcase if this is a (singular) test; otherwise-1
.private Quality
qual
The phase of this testcase.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.(package private) static long
TIME_SCHEDULED
private static long
TIME_SUITE
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
TestCase(Description desc)
Creates a new testcase based on the descriptiondesc
with indices0...n-1
, wheren
is the testcout ofdesc
.private
TestCase(Description desc, int idxTest)
Creates a new testcase based on the descriptiondesc
with indicesidxTest...idxTest+n-1
, wheren
is the testcout ofdesc
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) boolean
fullSuccess()
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) Description
getDesc()
Returns the description of this testcase given bydesc
.(package private) int
getIdx()
Returns the index of this testcase as described inidxTest
.(package private) Quality
getQuality()
Returns the phase of this testcase as described inqual
.(package private) java.lang.Throwable
getThrown()
Returnsnull
if no failure occurred.(package private) long
getTime()
If this testcase is a single testcase which has been finished, this is the span of time required to run this test.(package private) boolean
hasFailed()
Returns whethergetThrown()
returns non-null
.(package private) boolean
isTest()
Returns whether this testcase is a (singular) test.(package private) void
setAssumptionFailure(Failure failure)
Triggers a transition of the current phase if the assumption failurefailure
occurs.(package private) void
setFailure(Failure failure)
Triggers a transition of the current phase if the non-assumption failurefailure
occurs.(package private) void
setFinished()
Triggers a transition of the current phase given by finishing the run of a singular testcase if possible as specified byQuality.setFinished()
.(package private) void
setQualStartedIgnored(Quality qual)
Triggers a transition of the current phase toqual
if possible; otherwise throws an exception.(package private) void
setScheduledRec()
Recursively triggers a transition of the current phase toQuality.Scheduled
: If this is a test, just setqual
toQuality.Scheduled
if possible updatingfailure
andtime
.(package private) int
testCount()
Returns the number of singular test in this testcase.java.lang.String
toString()
-
-
-
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()
ornull
if 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-1
if there aren
singular test.
-
qual
private Quality qual
The phase of this testcase. The phase isnull
iff 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 isnull
iff-
this is a test suite according to
isTest()
and thusqual
isnull
. -
this is a singular test
(thus the phase
qual
is 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 is0
and 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 descriptiondesc
with indices0...n-1
, wheren
is the testcout ofdesc
. This testcase is the root of a hierarchy of tests which consists of a single test ifdesc
is 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 descriptiondesc
with indicesidxTest...idxTest+n-1
, wheren
is the testcout ofdesc
. This testcase is the root of a hierarchy of tests which consists of a single test ifdesc
is 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 is1
iff 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:
null
if 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()
Returnsnull
if no failure occurred. It returns non-null
iffqual
isQuality.Error
,Quality.Failure
orQuality.Invalidated
. In particular, it returnsnull
ifqual
isnull
.- Returns:
- the throwable defined by
failure
if 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 is0
and 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 setqual
toQuality.Scheduled
if possible updatingfailure
andtime
. If this is a suite, go recursively into thechildren
.- Throws:
java.lang.IllegalStateException
- if it is not allowed to set the phase toQuality.Scheduled
according toQuality.setScheduled()
.
-
setQualStartedIgnored
void setQualStartedIgnored(Quality qual)
Triggers a transition of the current phase toqual
if possible; otherwise throws an exception.- Parameters:
qual
- eitherQuality.Started
orQuality.Ignored
.- Throws:
java.lang.IllegalStateException
--
if
qual
is neitherQuality.Started
norQuality.Ignored
and in particular if it isnull
. -
if
qual
does not allow the transition toqual
.
-
if
java.lang.NullPointerException
- if this is a test suite and thusqual
isnull
.
-
setFailure
void setFailure(Failure failure)
Triggers a transition of the current phase if the non-assumption failurefailure
occurs. This presupposes that this is a singular test and that the current phase isQuality.Started
. The new phase is eitherQuality.Failure
orQuality.Error
depending 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
- iffailure
represents anAssumptionViolatedException
viaFailure.getException()
.java.lang.IllegalStateException
- iffailure
does not represent anAssumptionViolatedException
, this is a singular test andqual
does not allow the transition given by a failurefailure
, i.e.qual
is notQuality.Started
.java.lang.NullPointerException
- iffailure
does not represent anAssumptionViolatedException
and this is a test suite and thusqual
isnull
.- See Also:
setAssumptionFailure(Failure)
,Quality.setFailure(Throwable)
-
setAssumptionFailure
void setAssumptionFailure(Failure failure)
Triggers a transition of the current phase if the assumption failurefailure
occurs. 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
- iffailure
does not represent anAssumptionViolatedException
viaFailure.getException()
.java.lang.IllegalStateException
- iffailure
represents anAssumptionViolatedException
, this is a singlar test andqual
does not allow the transition toQuality.Invalidated
.java.lang.NullPointerException
- iffailure
represents anAssumptionViolatedException
and this is a test suite and thusqual
isnull
.- 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.Invalidated
andQuality.Error
Quality.Success
for current phaseQuality.Started
.
time
to the time required to run this testcase.- Throws:
java.lang.IllegalStateException
- if this is a singular test andqual
does not allow the transition by finishing a test case. This is the case for statesQuality.Scheduled
,Quality.Success
andQuality.Ignored
.java.lang.NullPointerException
- if this is a test suite and thusqual
isnull
.- See Also:
setFailure(Failure)
- remains unchanged for phases
-
-