Skip to content

Commit 07ef5e7

Browse files
authored
Improve Testkit Executions documentation (#5534)
* Deprecate Execution::started to avoid ambiguity. Executions are only ever skipped or finished. * Document that executions are created from events. * Document that execution either coincide with a skipped event or span started and finished event. * Document that aborted, succeeded and failed executions are subsets of finished.
1 parent 93a55de commit 07ef5e7

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

documentation/modules/ROOT/partials/release-notes/release-notes-6.1.0-M2.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ repository on GitHub.
2525
[[v6.1.0-M2-junit-platform-deprecations-and-breaking-changes]]
2626
==== Deprecations and Breaking Changes
2727

28-
* ❓
28+
* Deprecate `Executions.started()` in favor of `Executions.finished()`. Started executions are
29+
always finished.
2930

3031
[[v6.1.0-M2-junit-platform-new-features-and-improvements]]
3132
==== New Features and Improvements

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Events.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.assertj.core.data.Index;
3939
import org.jspecify.annotations.Nullable;
4040
import org.junit.platform.commons.util.Preconditions;
41+
import org.junit.platform.engine.TestDescriptor;
4142
import org.junit.platform.engine.TestExecutionResult;
4243
import org.junit.platform.engine.TestExecutionResult.Status;
4344
import org.opentest4j.AssertionFailedError;
@@ -121,6 +122,14 @@ public Stream<Event> filter(Predicate<? super Event> predicate) {
121122

122123
/**
123124
* Get the {@link Executions} for the current set of {@linkplain Event events}.
125+
* <p>
126+
* The set of executions is derived from the current set of events by
127+
* taking single {@linkplain Event#executionSkipped(TestDescriptor, String)
128+
* execution skipped} events and pairs of {@linkplain Event#executionStarted(TestDescriptor)
129+
* execution started} and {@linkplain Event#executionFinished(TestDescriptor, TestExecutionResult)
130+
* execution finished} events. As a consequence, executions for which either
131+
* the started or finished event is not included in the current set of
132+
* events are not included.
124133
*
125134
* @return an instance of {@code Executions} for the current set of events;
126135
* never {@code null}

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Execution.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
import org.apiguardian.api.API;
1919
import org.junit.platform.commons.util.Preconditions;
2020
import org.junit.platform.commons.util.ToStringBuilder;
21+
import org.junit.platform.engine.EngineExecutionListener;
2122
import org.junit.platform.engine.TestDescriptor;
2223
import org.junit.platform.engine.TestExecutionResult;
2324

2425
/**
2526
* {@code Execution} encapsulates metadata for the execution of a single
2627
* {@link TestDescriptor}.
28+
* <p>
29+
* The execution either coincides with a single
30+
* {@linkplain EngineExecutionListener#executionSkipped(TestDescriptor, String) skipped} event or spans a
31+
* {@linkplain EngineExecutionListener#executionStarted(TestDescriptor) execution started} and
32+
* {@linkplain EngineExecutionListener#executionFinished(TestDescriptor, TestExecutionResult) execution finished} event.
2733
*
2834
* @since 1.4
2935
*/

junit-platform-testkit/src/main/java/org/junit/platform/testkit/engine/Executions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
package org.junit.platform.testkit.engine;
1212

13+
import static org.apiguardian.api.API.Status.DEPRECATED;
1314
import static org.apiguardian.api.API.Status.MAINTAINED;
1415

1516
import java.io.OutputStream;
@@ -45,6 +46,7 @@ public final class Executions {
4546

4647
private Executions(Stream<Execution> executions, String category) {
4748
Preconditions.notNull(executions, "Execution stream must not be null");
49+
Preconditions.notNull(category, "Category must not be null");
4850

4951
this.executions = executions.toList();
5052
this.category = category;
@@ -53,6 +55,7 @@ private Executions(Stream<Execution> executions, String category) {
5355
Executions(List<Event> events, String category) {
5456
Preconditions.notNull(events, "Event list must not be null");
5557
Preconditions.containsNoNullElements(events, "Event list must not contain null elements");
58+
Preconditions.notNull(category, "Category must not be null");
5659

5760
this.executions = List.copyOf(createExecutions(events));
5861
this.category = category;
@@ -122,6 +125,8 @@ public long count() {
122125

123126
/**
124127
* Get the skipped {@link Executions} contained in this {@code Executions} object.
128+
* <p>
129+
* Executions that are not skipped are {@linkplain #finished() finished}.
125130
*
126131
* @return the filtered {@code Executions}; never {@code null}
127132
*/
@@ -131,15 +136,24 @@ public Executions skipped() {
131136

132137
/**
133138
* Get the started {@link Executions} contained in this {@code Executions} object.
139+
* <p>
140+
* Executions that are not started are {@linkplain #skipped() skipped}.
134141
*
135142
* @return the filtered {@code Executions}; never {@code null}
143+
*
144+
* @deprecated by definition, all started executions are also finished executions.
145+
* Use {@link #finished()} instead.
136146
*/
147+
@Deprecated(since = "6.1", forRemoval = true)
148+
@API(status = DEPRECATED, since = "6.1")
137149
public Executions started() {
138150
return new Executions(executionsByTerminationInfo(TerminationInfo::notSkipped), this.category + " Started");
139151
}
140152

141153
/**
142154
* Get the finished {@link Executions} contained in this {@code Executions} object.
155+
* <p>
156+
* Executions that are not finished are {@linkplain #skipped() skipped}.
143157
*
144158
* @return the filtered {@code Executions}; never {@code null}
145159
*/
@@ -149,6 +163,8 @@ public Executions finished() {
149163

150164
/**
151165
* Get the aborted {@link Executions} contained in this {@code Executions} object.
166+
* <p>
167+
* The aborted executions are a subset of the {@linkplain #finished() finished} executions.
152168
*
153169
* @return the filtered {@code Executions}; never {@code null}
154170
*/
@@ -158,6 +174,8 @@ public Executions aborted() {
158174

159175
/**
160176
* Get the succeeded {@link Executions} contained in this {@code Executions} object.
177+
* <p>
178+
* The succeeded executions are a subset of the {@linkplain #finished() finished} executions.
161179
*
162180
* @return the filtered {@code Executions}; never {@code null}
163181
*/
@@ -167,6 +185,8 @@ public Executions succeeded() {
167185

168186
/**
169187
* Get the failed {@link Executions} contained in this {@code Executions} object.
188+
* <p>
189+
* The failed executions are a subset of the {@linkplain #finished() finished} executions.
170190
*
171191
* @return the filtered {@code Executions}; never {@code null}
172192
*/

platform-tests/src/test/java/org/junit/platform/testkit/engine/ExecutionsIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void executionsFromSkippedTestEvents() {
3737
}
3838

3939
@Test
40+
@SuppressWarnings("removal")
4041
void executionsFromStartedTestEvents() {
4142
var testEvents = getTestEvents();
4243

0 commit comments

Comments
 (0)