- java.lang.Object
-
- org.junit.platform.launcher.TestPlan
-
@API(status=STABLE, since="1.0") public class TestPlan extends Object
TestPlandescribes the tree of tests and containers as discovered by aLauncher.Tests and containers are represented by
TestIdentifierinstances. The complete set of identifiers comprises a tree-like structure. However, each identifier only stores the unique ID of its parent. This class provides a number of helpful methods to retrieve the parent, children, and descendants of an identifier.While the contained instances of
TestIdentifierare immutable, instances of this class contain mutable state. For example, when a dynamic test is registered at runtime, it is added to the original test plan and reported toTestExecutionListenerimplementations.This class is not intended to be extended by clients.
- Since:
- 1.0
- See Also:
Launcher,TestExecutionListener
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTestPlan(boolean containsTests)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(TestIdentifier testIdentifier)Deprecated.Please discontinue use of this method.booleancontainsTests()Return whether this test plan contains any tests.longcountTestIdentifiers(Predicate<? super TestIdentifier> predicate)Count allTestIdentifiersthat satisfy the given predicate.static TestPlanfrom(Collection<TestDescriptor> engineDescriptors)Construct a newTestPlanfrom the supplied collection ofTestDescriptors.Set<TestIdentifier>getChildren(String parentId)Get the children of the supplied unique ID.Set<TestIdentifier>getChildren(TestIdentifier parent)Get the children of the suppliedTestIdentifier.Set<TestIdentifier>getDescendants(TestIdentifier parent)Get all descendants of the suppliedTestIdentifier(i.e., all of its children and their children, recursively).Optional<TestIdentifier>getParent(TestIdentifier child)Get the parent of the suppliedTestIdentifier.Set<TestIdentifier>getRoots()Get the rootTestIdentifiersfor this test plan.TestIdentifiergetTestIdentifier(String uniqueId)Get theTestIdentifierwith the supplied unique ID.
-
-
-
Method Detail
-
from
@API(status=INTERNAL, since="1.0") public static TestPlan from(Collection<TestDescriptor> engineDescriptors)
Construct a newTestPlanfrom the supplied collection ofTestDescriptors.Each supplied
TestDescriptoris expected to be a descriptor for aTestEngine.- Parameters:
engineDescriptors- the engine test descriptors from which the test plan should be created; nevernull- Returns:
- a new test plan
-
add
@Deprecated @API(status=DEPRECATED, since="1.4") public void add(TestIdentifier testIdentifier)
Deprecated.Please discontinue use of this method. A future version of the JUnit Platform will ignore this call and eventually even throw an exception.Add the suppliedTestIdentifierto this test plan.- Parameters:
testIdentifier- the identifier to add; nevernull
-
getRoots
public Set<TestIdentifier> getRoots()
Get the rootTestIdentifiersfor this test plan.- Returns:
- an unmodifiable set of the root identifiers
-
getParent
public Optional<TestIdentifier> getParent(TestIdentifier child)
Get the parent of the suppliedTestIdentifier.- Parameters:
child- the identifier to look up the parent for; nevernull- Returns:
- an
Optionalcontaining the parent, if present
-
getChildren
public Set<TestIdentifier> getChildren(TestIdentifier parent)
Get the children of the suppliedTestIdentifier.- Parameters:
parent- the identifier to look up the children for; nevernull- Returns:
- an unmodifiable set of the parent's children, potentially empty
- See Also:
getChildren(String)
-
getChildren
public Set<TestIdentifier> getChildren(String parentId)
Get the children of the supplied unique ID.- Parameters:
parentId- the unique ID to look up the children for; nevernullor blank- Returns:
- an unmodifiable set of the parent's children, potentially empty
- See Also:
getChildren(TestIdentifier)
-
getTestIdentifier
public TestIdentifier getTestIdentifier(String uniqueId) throws PreconditionViolationException
Get theTestIdentifierwith the supplied unique ID.- Parameters:
uniqueId- the unique ID to look up the identifier for; nevernullor blank- Returns:
- the identifier with the supplied unique ID; never
null - Throws:
PreconditionViolationException- if noTestIdentifierwith the supplied unique ID is present in this test plan
-
countTestIdentifiers
public long countTestIdentifiers(Predicate<? super TestIdentifier> predicate)
Count allTestIdentifiersthat satisfy the given predicate.- Parameters:
predicate- a predicate which returnstruefor identifiers to be counted; nevernull- Returns:
- the number of identifiers that satisfy the supplied predicate
-
getDescendants
public Set<TestIdentifier> getDescendants(TestIdentifier parent)
Get all descendants of the suppliedTestIdentifier(i.e., all of its children and their children, recursively).- Parameters:
parent- the identifier to look up the descendants for; nevernull- Returns:
- an unmodifiable set of the parent's descendants, potentially empty
-
containsTests
public boolean containsTests()
Return whether this test plan contains any tests.A test plan contains tests, if at least one of the contained engine descriptors contains tests.
- Returns:
trueif this test plan contains tests- See Also:
TestDescriptor.containsTests(TestDescriptor)
-
-