Package org.junit.runner
Class Description
java.lang.Object
org.junit.runner.Description
- All Implemented Interfaces:
Serializable
A
Description
describes a test which is to be run or has been run. Descriptions
can be atomic (a single test) or compound (containing children tests). Descriptions
are used
to provide feedback about the tests that are about to run (for example, the tree view
visible in many IDEs) or tests that have been run (for example, the failures view).
Descriptions
are implemented as a single class rather than a Composite because
they are entirely informational. They contain no logic aside from counting their tests.
In the past, we used the raw TestCase
s and TestSuite
s
to display the tree of tests. This was no longer viable in JUnit 4 because atomic tests no longer have
a superclass below Object
. We needed a way to pass a class and name together. Description
emerged from this.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Description
Describes a Runner which runs no testsprivate final Annotation[]
private final Collection<Description>
private final String
private Class<?>
private final Serializable
private static final Pattern
private static final long
static final Description
Describes a step in the test-running mechanism that goes so wrong no other description can be used (for example, an exception thrown from a Runner's constructor -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Description
(Class<?> testClass, String displayName, Serializable uniqueId, Annotation... annotations) private
Description
(Class<?> clazz, String displayName, Annotation... annotations) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(Description description) AddDescription
as a child of the receiver.static Description
createSuiteDescription
(Class<?> testClass) Create aDescription
named aftertestClass
static Description
createSuiteDescription
(Class<?> testClass, Annotation... annotations) Create aDescription
named aftertestClass
static Description
createSuiteDescription
(String name, Serializable uniqueId, Annotation... annotations) Create aDescription
namedname
.static Description
createSuiteDescription
(String name, Annotation... annotations) Create aDescription
namedname
.static Description
createTestDescription
(Class<?> clazz, String name) Create aDescription
of a single test namedname
in the classclazz
.static Description
createTestDescription
(Class<?> clazz, String name, Annotation... annotations) Create aDescription
of a single test namedname
in the classclazz
.static Description
createTestDescription
(String className, String name, Serializable uniqueId) Create aDescription
of a single test namedname
in the classclazz
.static Description
createTestDescription
(String className, String name, Annotation... annotations) Create aDescription
of a single test namedname
in the 'class' namedclassName
.boolean
private static String
formatDisplayName
(String name, String className) <T extends Annotation>
TgetAnnotation
(Class<T> annotationType) Gets the copy of the children of thisDescription
.Class<?>
int
hashCode()
boolean
isEmpty()
boolean
isSuite()
boolean
isTest()
private String
methodAndClassNamePatternGroupOrDefault
(int group, String defaultString) int
toString()
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
METHOD_AND_CLASS_NAME_PATTERN
-
EMPTY
Describes a Runner which runs no tests -
TEST_MECHANISM
Describes a step in the test-running mechanism that goes so wrong no other description can be used (for example, an exception thrown from a Runner's constructor -
fChildren
-
fDisplayName
-
fUniqueId
-
fAnnotations
-
fTestClass
-
-
Constructor Details
-
Description
-
Description
private Description(Class<?> testClass, String displayName, Serializable uniqueId, Annotation... annotations)
-
-
Method Details
-
createSuiteDescription
Create aDescription
namedname
. Generally, you will add children to thisDescription
.- Parameters:
name
- the name of theDescription
annotations
- meta-data about the test, for downstream interpreters- Returns:
- a
Description
namedname
-
createSuiteDescription
public static Description createSuiteDescription(String name, Serializable uniqueId, Annotation... annotations) Create aDescription
namedname
. Generally, you will add children to thisDescription
.- Parameters:
name
- the name of theDescription
uniqueId
- an arbitrary object used to define uniqueness (inequals(Object)
annotations
- meta-data about the test, for downstream interpreters- Returns:
- a
Description
namedname
-
createTestDescription
public static Description createTestDescription(String className, String name, Annotation... annotations) Create aDescription
of a single test namedname
in the 'class' namedclassName
. Generally, this will be a leafDescription
. This method is a better choice thancreateTestDescription(Class, String, Annotation...)
for test runners whose test cases are not defined in an actual JavaClass
.- Parameters:
className
- the class name of the testname
- the name of the test (a method name for test annotated withTest
)annotations
- meta-data about the test, for downstream interpreters- Returns:
- a
Description
namedname
-
createTestDescription
public static Description createTestDescription(Class<?> clazz, String name, Annotation... annotations) Create aDescription
of a single test namedname
in the classclazz
. Generally, this will be a leafDescription
.- Parameters:
clazz
- the class of the testname
- the name of the test (a method name for test annotated withTest
)annotations
- meta-data about the test, for downstream interpreters- Returns:
- a
Description
namedname
-
createTestDescription
Create aDescription
of a single test namedname
in the classclazz
. Generally, this will be a leafDescription
. (This remains for binary compatibility with clients of JUnit 4.3)- Parameters:
clazz
- the class of the testname
- the name of the test (a method name for test annotated withTest
)- Returns:
- a
Description
namedname
-
createTestDescription
public static Description createTestDescription(String className, String name, Serializable uniqueId) Create aDescription
of a single test namedname
in the classclazz
. Generally, this will be a leafDescription
.- Parameters:
name
- the name of the test (a method name for test annotated withTest
)- Returns:
- a
Description
namedname
-
formatDisplayName
-
createSuiteDescription
Create aDescription
named aftertestClass
- Parameters:
testClass
- AClass
containing tests- Returns:
- a
Description
oftestClass
-
createSuiteDescription
Create aDescription
named aftertestClass
- Parameters:
testClass
- A not nullClass
containing testsannotations
- meta-data about the test, for downstream interpreters- Returns:
- a
Description
oftestClass
-
getDisplayName
- Returns:
- a user-understandable label
-
addChild
AddDescription
as a child of the receiver.- Parameters:
description
- the soon-to-be child.
-
getChildren
Gets the copy of the children of thisDescription
. Returns an empty list if there are no children. -
isSuite
public boolean isSuite()- Returns:
true
if the receiver is a suite
-
isTest
public boolean isTest()- Returns:
true
if the receiver is an atomic test
-
testCount
public int testCount()- Returns:
- the total number of atomic tests in the receiver
-
hashCode
public int hashCode() -
equals
-
toString
-
isEmpty
public boolean isEmpty()- Returns:
- true if this is a description of a Runner that runs no tests
-
childlessCopy
- Returns:
- a copy of this description, with no children (on the assumption that some of the children will be added back)
-
getAnnotation
- Returns:
- the annotation of type annotationType that is attached to this description node, or null if none exists
-
getAnnotations
- Returns:
- all of the annotations attached to this description node
-
getTestClass
- Returns:
- If this describes a method invocation, the class of the test instance.
-
getClassName
- Returns:
- If this describes a method invocation, the name of the class of the test instance
-
getMethodName
- Returns:
- If this describes a method invocation, the name of the method (or null if not)
-
methodAndClassNamePatternGroupOrDefault
-