Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jun 30, 2023
1 parent 607e028 commit 1f36bc8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JUnit repository on GitHub.
<<../user-guide/index.adoc#stacktrace-pruning, User Guide>> for details.
* New `getAncestors()` method in `TestDescriptor`.


[[release-notes-5.10.0-RC1-junit-jupiter]]
=== JUnit Jupiter

Expand Down
11 changes: 6 additions & 5 deletions documentation/src/docs/asciidoc/user-guide/running-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,15 @@ give it a try and provide feedback to the JUnit team so they can improve and eve
<<api-evolution, promote>> this feature.

[[stacktrace-pruning]]
=== Stack trace pruning
=== Stack Trace Pruning

Since version 1.10, the JUnit Platform provides built-in support for pruning stack traces
produced by failing tests. This feature can be enabled or disabled via the
`junit.platform.stacktrace.pruning.enabled` _configuration parameter_.
produced by failing tests. This feature is enabled by default but can be disabled by
setting the `junit.platform.stacktrace.pruning.enabled` _configuration parameter_ to
`false`.

If enabled, all calls from the `org.junit`, `jdk.internal.reflect`, and `sun.reflect`
packages are removed from the stack trace, unless they are subsequent to the test itself
When enabled, all calls from the `org.junit`, `jdk.internal.reflect`, and `sun.reflect`
packages are removed from the stack trace, unless the calls occur after the test itself
or any of its ancestors. For that reason, calls to `{Assertions}` or `{Assumptions}` will
never be excluded.

Expand Down
10 changes: 5 additions & 5 deletions documentation/src/docs/asciidoc/user-guide/writing-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2302,11 +2302,11 @@ might conflict with the configured execution order. Thus, in both cases, test me
such test classes are only executed concurrently if the `@Execution(CONCURRENT)`
annotation is present on the test class or method.

When parallel execution is enabled and a default `{ClassOrderer}` (see
<<writing-tests-test-execution-order-classes>> for details) is registered, top-level test
classes will initially be sorted accordingly and scheduled in that order. However, they
are not guaranteed to be started in exactly that order since the threads they are executed
on are not controlled directly by JUnit.
When parallel execution is enabled and a default `{ClassOrderer}` is registered (see
<<writing-tests-test-execution-order-classes>> for details), top-level test classes will
initially be sorted accordingly and scheduled in that order. However, they are not
guaranteed to be started in exactly that order since the threads they are executed on are
not controlled directly by JUnit.

All nodes of the test tree that are configured with the `CONCURRENT` execution mode will
be executed fully in parallel according to the provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,25 @@ public static String readStackTrace(Throwable throwable) {

/**
* Prune the stack trace of the supplied {@link Throwable} by removing
* elements from the {@code org.junit}, {@code jdk.internal.reflect} and
* {@code sun.reflect} packages. If an element matching one of the supplied
* class names is encountered, all following elements will be kept regardless.
* {@linkplain StackTraceElement stack trace elements} from the {@code org.junit},
* {@code jdk.internal.reflect}, and {@code sun.reflect} packages. If a
* {@code StackTraceElement} matching one of the supplied {@code classNames}
* is encountered, all subsequent elements in the stack trace will be retained.
*
* <p>Additionally, all elements prior to and including the first
* JUnit Launcher call will be removed.
* <p>Additionally, all elements prior to and including the first JUnit Platform
* Launcher call will be removed.
*
* @param throwable the {@code Throwable} whose stack trace should be
* pruned; never {@code null}
* @param testClassNames the test class names that should stop the pruning
* if encountered; never {@code null}
* @param throwable the {@code Throwable} whose stack trace should be pruned;
* never {@code null}
* @param classNames the class names that should stop the pruning if encountered;
* never {@code null}
*
* @since 5.10
* @since 1.10
*/
@API(status = INTERNAL, since = "5.10")
public static void pruneStackTrace(Throwable throwable, List<String> testClassNames) {
@API(status = INTERNAL, since = "1.10")
public static void pruneStackTrace(Throwable throwable, List<String> classNames) {
Preconditions.notNull(throwable, "Throwable must not be null");
Preconditions.notNull(testClassNames, "List of test class names must not be null");
Preconditions.notNull(classNames, "List of class names must not be null");

List<StackTraceElement> stackTrace = Arrays.asList(throwable.getStackTrace());
List<StackTraceElement> prunedStackTrace = new ArrayList<>();
Expand All @@ -124,7 +125,7 @@ public static void pruneStackTrace(Throwable throwable, List<String> testClassNa
StackTraceElement element = stackTrace.get(i);
String className = element.getClassName();

if (testClassNames.contains(className)) {
if (classNames.contains(className)) {
// Include all elements called by the test
prunedStackTrace.addAll(stackTrace.subList(i, stackTrace.size()));
break;
Expand All @@ -142,16 +143,16 @@ else if (STACK_TRACE_ELEMENT_FILTER.test(className)) {
}

/**
* Find all causes and suppressed exceptions in the backtrace of the
* Find all causes and suppressed exceptions in the stack trace of the
* supplied {@link Throwable}.
*
* @param rootThrowable the {@code Throwable} to explore; never {@code null}
* @return an immutable list of all throwables found, including the supplied
* one; never {@code null}
*
* @since 5.10
* @since 1.10
*/
@API(status = INTERNAL, since = "5.10")
@API(status = INTERNAL, since = "1.10")
public static List<Throwable> findNestedThrowables(Throwable rootThrowable) {
Preconditions.notNull(rootThrowable, "Throwable must not be null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ default String getLegacyReportingName() {
/**
* Get the immutable set of all <em>ancestors</em> of this descriptor.
*
* <p>An <em>ancestors</em> is the parent of this descriptor or the parent
* of one of its parents, recursively.
* <p>An <em>ancestor</em> is the parent of this descriptor or the parent of
* one of its parents, recursively.
*
* @see #getParent()
*/
Expand All @@ -122,7 +122,10 @@ default Set<? extends TestDescriptor> getAncestors() {
TestDescriptor parent = getParent().get();
Set<TestDescriptor> ancestors = new LinkedHashSet<>();
ancestors.add(parent);
ancestors.addAll(parent.getAncestors());
// Need to recurse?
if (parent.getParent().isPresent()) {
ancestors.addAll(parent.getAncestors());
}
return Collections.unmodifiableSet(ancestors);
}

Expand Down

0 comments on commit 1f36bc8

Please sign in to comment.