org.junit.runner

Class 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.

See Also:
Request, Runner

Field Summary

static Description
EMPTY
static Description
TEST_MECHANISM

Method Summary

@Override
String toString()
void
addChild(Description description)
Add Description as a child of the receiver.
@Override
boolean equals(Object obj)
static Description
createSuiteDescription(Class testClass)
Create a Description named after testClass
static Description
createSuiteDescription(String name)
Create a Description named name.
static Description
createTestDescription(Class clazz, String name)
Create a Description of a single test named name in the class clazz.
ArrayList
getChildren()
String
getDisplayName()
@Override
int hashCode()
boolean
isSuite()
boolean
isTest()
int
testCount()

Field Details

EMPTY

public static final Description EMPTY

TEST_MECHANISM

public static final Description TEST_MECHANISM

Method Details

String toString

public @Override String toString()

addChild

public void addChild(Description description)
Add Description as a child of the receiver.
Parameters:
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
Parameters:
testClass - A Class containing tests
Returns:
a Description of testClass

createSuiteDescription

public static Description createSuiteDescription(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(Class clazz,
                                                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

getChildren

public ArrayList getChildren()
Returns:
the receiver's children, if any

getDisplayName

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

int hashCode

public @Override int hashCode()

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