org.junit.runner
Class Description

java.lang.Object
  extended by org.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 TestCases and 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.

See Also:
Request, Runner

Field Summary
static Description EMPTY
           
static Description TEST_MECHANISM
           
 
Constructor Summary
protected Description(java.lang.String displayName)
          Deprecated. (since 4.3) use the static factories (createTestDescription, createSuiteDescription) instead
 
Method Summary
 void addChild(Description description)
          Add Description as a child of the receiver.
static Description createSuiteDescription(java.lang.Class<?> testClass)
          Create a Description named after testClass
static Description createSuiteDescription(java.lang.String name)
          Create a Description named name.
static Description createTestDescription(java.lang.Class<?> clazz, java.lang.String name)
          Create a Description of a single test named name in the class clazz.
 boolean equals(java.lang.Object obj)
           
 java.util.ArrayList<Description> getChildren()
           
 java.lang.String getDisplayName()
           
 int hashCode()
           
 boolean isSuite()
           
 boolean isTest()
           
 int testCount()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final Description EMPTY

TEST_MECHANISM

public static final Description TEST_MECHANISM
Constructor Detail

Description

@Deprecated
protected Description(java.lang.String displayName)
Deprecated. (since 4.3) use the static factories (createTestDescription, createSuiteDescription) instead

Method Detail

createSuiteDescription

public static Description createSuiteDescription(java.lang.String name)
Create a Description named name. Generally, you will add children to this Description.

Parameters:
name - the name of the Description
Returns:
a Description named name

createTestDescription

public static Description createTestDescription(java.lang.Class<?> clazz,
                                                java.lang.String name)
Create a Description of a single test named name in the class clazz. Generally, this will be a leaf Description.

Parameters:
clazz - the class of the test
name - the name of the test (a method name for test annotated with Test)
Returns:
a Description named name

createSuiteDescription

public static Description createSuiteDescription(java.lang.Class<?> testClass)
Create a Description named after testClass

Parameters:
testClass - A Class containing tests
Returns:
a Description of testClass

getDisplayName

public java.lang.String getDisplayName()
Returns:
a user-understandable label

addChild

public void addChild(Description description)
Add Description as a child of the receiver.

Parameters:
description - the soon-to-be child.

getChildren

public java.util.ArrayList<Description> getChildren()
Returns:
the receiver's children, if any

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()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object