org.junit.runner
Class Description
java.lang.Objectorg.junit.runner.Description
public class Description
extends java.lang.Object
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
junit.framework.TestCases and
junit.framework.TestSuites
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.
TEST_MECHANISM
public static final Description TEST_MECHANISM
String toString
public @Override String toString()
addChild
public void addChild(Description description)
Add Description as a child of the receiver.
description - the soon-to-be child.
boolean equals
public @Override boolean equals(Object obj)
createSuiteDescription
public static Description createSuiteDescription(Class> testClass)
Create a Description named after testClass
testClass - A Class containing tests
- a
Description of testClass
createSuiteDescription
public static Description createSuiteDescription(String name)
Create a Description named name.
Generally, you will add children to this Description.
name - the name of the Description
createTestDescription
public static Description createTestDescription(Class> clazz,
String name) Create a Description of a single test named name in the class clazz.
Generally, this will be a leaf Description.
clazz - the class of the testname - the name of the test (a method name for test annotated with Test)
getChildren
public ArrayList getChildren()
- the receiver's children, if any
getDisplayName
public String getDisplayName()
- a user-understandable label
int hashCode
public @Override int hashCode()
isSuite
public boolean isSuite()
true if the receiver is a suite
isTest
public boolean isTest()
true if the receiver is an atomic test
testCount
public int testCount()
- the total number of atomic tests in the receiver