-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ExtensionContext.getTestInstances() API
The new `getTestInstances()` and `getRequiredTestInstances()` methods of `ExtensionContext` allow accessing all test instances, including enclosing ones for `@Nested` tests. Resolves #1618.
- Loading branch information
1 parent
c804c80
commit f42aede
Showing
21 changed files
with
495 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/TestInstances.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2015-2018 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code TestInstances} encapsulates the <em>test instances</em> of a test. | ||
* | ||
* <p>While top-level tests only have a single test instance, nested tests | ||
* have one additional instance for each enclosing test class. | ||
* | ||
* @since 5.4 | ||
* @see ExtensionContext#getTestInstances() | ||
* @see ExtensionContext#getRequiredTestInstances() | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.4") | ||
public interface TestInstances { | ||
|
||
/** | ||
* Get the innermost test instance. | ||
* | ||
* <p>The innermost instance is the one closest to the test method. | ||
* | ||
* @return the innermost test instance; never {@code null} | ||
*/ | ||
Object getInnermostInstance(); | ||
|
||
/** | ||
* Get the enclosing test instances, excluding the innermost test instance, | ||
* ordered from outermost to innermost. | ||
* | ||
* @return the enclosing test instances; never {@code null} or containing | ||
* {@code null}, but potentially empty | ||
*/ | ||
List<Object> getEnclosingInstances(); | ||
|
||
/** | ||
* Get all test instances, ordered from outermost to innermost. | ||
* | ||
* @return all test instances; never {@code null}, containing {@code null}, | ||
* or empty | ||
*/ | ||
List<Object> getAllInstances(); | ||
|
||
/** | ||
* Find the first test instance that is an instance of the supplied required | ||
* type, checking from innermost to outermost. | ||
* | ||
* @param requiredType the type to search for | ||
* @return the first test instance of the required type; never {@code null} | ||
* but potentially empty | ||
*/ | ||
<T> Optional<T> findInstance(Class<T> requiredType); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.