Package org.junit.runner
Class Description
- java.lang.Object
-
- org.junit.runner.Description
-
- All Implemented Interfaces:
java.io.Serializable
public class Description extends java.lang.Object implements java.io.Serializable
ADescriptiondescribes a test which is to be run or has been run.Descriptionscan be atomic (a single test) or compound (containing children tests).Descriptionsare 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).Descriptionsare 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
TestCases andTestSuites to display the tree of tests. This was no longer viable in JUnit 4 because atomic tests no longer have a superclass belowObject. We needed a way to pass a class and name together. Description emerged from this.- Since:
- 4.0
- See Also:
Request,Runner, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DescriptionEMPTYDescribes a Runner which runs no testsstatic DescriptionTEST_MECHANISMDescribes 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
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Description description)AddDescriptionas a child of the receiver.DescriptionchildlessCopy()static DescriptioncreateSuiteDescription(java.lang.Class<?> testClass)Create aDescriptionnamed aftertestClassstatic DescriptioncreateSuiteDescription(java.lang.Class<?> testClass, java.lang.annotation.Annotation... annotations)Create aDescriptionnamed aftertestClassstatic DescriptioncreateSuiteDescription(java.lang.String name, java.io.Serializable uniqueId, java.lang.annotation.Annotation... annotations)Create aDescriptionnamedname.static DescriptioncreateSuiteDescription(java.lang.String name, java.lang.annotation.Annotation... annotations)Create aDescriptionnamedname.static DescriptioncreateTestDescription(java.lang.Class<?> clazz, java.lang.String name)Create aDescriptionof a single test namednamein the classclazz.static DescriptioncreateTestDescription(java.lang.Class<?> clazz, java.lang.String name, java.lang.annotation.Annotation... annotations)Create aDescriptionof a single test namednamein the classclazz.static DescriptioncreateTestDescription(java.lang.String className, java.lang.String name, java.io.Serializable uniqueId)Create aDescriptionof a single test namednamein the classclazz.static DescriptioncreateTestDescription(java.lang.String className, java.lang.String name, java.lang.annotation.Annotation... annotations)Create aDescriptionof a single test namednamein the 'class' namedclassName.booleanequals(java.lang.Object obj)<T extends java.lang.annotation.Annotation>
TgetAnnotation(java.lang.Class<T> annotationType)java.util.Collection<java.lang.annotation.Annotation>getAnnotations()java.util.ArrayList<Description>getChildren()Gets the copy of the children of thisDescription.java.lang.StringgetClassName()java.lang.StringgetDisplayName()java.lang.StringgetMethodName()java.lang.Class<?>getTestClass()inthashCode()booleanisEmpty()booleanisSuite()booleanisTest()inttestCount()java.lang.StringtoString()
-
-
-
Field Detail
-
EMPTY
public static final Description EMPTY
Describes a Runner which runs no tests
-
TEST_MECHANISM
public static final Description 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
-
-
Method Detail
-
createSuiteDescription
public static Description createSuiteDescription(java.lang.String name, java.lang.annotation.Annotation... annotations)
Create aDescriptionnamedname. Generally, you will add children to thisDescription.- Parameters:
name- the name of theDescriptionannotations- meta-data about the test, for downstream interpreters- Returns:
- a
Descriptionnamedname
-
createSuiteDescription
public static Description createSuiteDescription(java.lang.String name, java.io.Serializable uniqueId, java.lang.annotation.Annotation... annotations)
Create aDescriptionnamedname. Generally, you will add children to thisDescription.- Parameters:
name- the name of theDescriptionuniqueId- an arbitrary object used to define uniqueness (inequals(Object)annotations- meta-data about the test, for downstream interpreters- Returns:
- a
Descriptionnamedname
-
createTestDescription
public static Description createTestDescription(java.lang.String className, java.lang.String name, java.lang.annotation.Annotation... annotations)
Create aDescriptionof a single test namednamein 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
Descriptionnamedname
-
createTestDescription
public static Description createTestDescription(java.lang.Class<?> clazz, java.lang.String name, java.lang.annotation.Annotation... annotations)
Create aDescriptionof a single test namednamein 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
Descriptionnamedname
-
createTestDescription
public static Description createTestDescription(java.lang.Class<?> clazz, java.lang.String name)
Create aDescriptionof a single test namednamein 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
Descriptionnamedname
-
createTestDescription
public static Description createTestDescription(java.lang.String className, java.lang.String name, java.io.Serializable uniqueId)
Create aDescriptionof a single test namednamein the classclazz. Generally, this will be a leafDescription.- Parameters:
name- the name of the test (a method name for test annotated withTest)- Returns:
- a
Descriptionnamedname
-
createSuiteDescription
public static Description createSuiteDescription(java.lang.Class<?> testClass)
Create aDescriptionnamed aftertestClass- Parameters:
testClass- AClasscontaining tests- Returns:
- a
DescriptionoftestClass
-
createSuiteDescription
public static Description createSuiteDescription(java.lang.Class<?> testClass, java.lang.annotation.Annotation... annotations)
Create aDescriptionnamed aftertestClass- Parameters:
testClass- A not nullClasscontaining testsannotations- meta-data about the test, for downstream interpreters- Returns:
- a
DescriptionoftestClass
-
getDisplayName
public java.lang.String getDisplayName()
- Returns:
- a user-understandable label
-
addChild
public void addChild(Description description)
AddDescriptionas a child of the receiver.- Parameters:
description- the soon-to-be child.
-
getChildren
public java.util.ArrayList<Description> getChildren()
Gets the copy of the children of thisDescription. Returns an empty list if there are no children.
-
isSuite
public boolean isSuite()
- Returns:
trueif the receiver is a suite
-
isTest
public boolean isTest()
- Returns:
trueif the receiver is an atomic test
-
testCount
public int testCount()
- Returns:
- the total number of atomic tests in the receiver
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isEmpty
public boolean isEmpty()
- Returns:
- true if this is a description of a Runner that runs no tests
-
childlessCopy
public Description childlessCopy()
- Returns:
- a copy of this description, with no children (on the assumption that some of the children will be added back)
-
getAnnotation
public <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.Class<T> annotationType)
- Returns:
- the annotation of type annotationType that is attached to this description node, or null if none exists
-
getAnnotations
public java.util.Collection<java.lang.annotation.Annotation> getAnnotations()
- Returns:
- all of the annotations attached to this description node
-
getTestClass
public java.lang.Class<?> getTestClass()
- Returns:
- If this describes a method invocation, the class of the test instance.
-
getClassName
public java.lang.String getClassName()
- Returns:
- If this describes a method invocation, the name of the class of the test instance
-
getMethodName
public java.lang.String getMethodName()
- Returns:
- If this describes a method invocation, the name of the method (or null if not)
-
-