-
-
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 support for ordering the sequence of test methods
These commits introduce new support in JUnit Jupiter for ordering the sequence of test methods. Specifically, these commits introduce a new MethodOrderer API that can be registered via a new @TestMethodOrder annotation. JUnit Jupiter provides the following built-in implementations of this new API. - Alphanumeric: sorts test methods alphanumerically based on their names and formal parameter lists. - OrderAnnotation: sorts test methods numerically based on values specified via the @order annotation. - Random: orders test methods pseudo-randomly and supports configuration of a custom seed. Consult the new "Test Execution Order" section of the User Guide for details and example usage. Issue: #13
- Loading branch information
Showing
17 changed files
with
1,311 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 example; | ||
|
||
// tag::user_guide[] | ||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
@TestMethodOrder(OrderAnnotation.class) | ||
class OrderedTestsDemo { | ||
|
||
@Test | ||
@Order(1) | ||
void nullValues() { | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void emptyValues() { | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
void validValues() { | ||
} | ||
} | ||
// end::user_guide[] |
80 changes: 80 additions & 0 deletions
80
junit-jupiter-api/src/main/java/org/junit/jupiter/api/MethodDescriptor.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,80 @@ | ||
/* | ||
* 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; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@link MethodDescriptor} encapsulates functionality for a given {@link Method}. | ||
* | ||
* @since 5.4 | ||
* @see MethodOrdererContext | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.4") | ||
public interface MethodDescriptor { | ||
|
||
/** | ||
* Get the method for this descriptor. | ||
* | ||
* @return the method; never {@code null} | ||
*/ | ||
Method getMethod(); | ||
|
||
/** | ||
* Determine if an annotation of {@code annotationType} is either | ||
* <em>present</em> or <em>meta-present</em> on the {@link Method} for | ||
* this descriptor. | ||
* | ||
* @param annotationType the annotation type to search for; never {@code null} | ||
* @return {@code true} if the annotation is present or meta-present | ||
* @see #findAnnotation(Class) | ||
* @see #findRepeatableAnnotations(Class) | ||
*/ | ||
boolean isAnnotated(Class<? extends Annotation> annotationType); | ||
|
||
/** | ||
* Find the first annotation of {@code annotationType} that is either | ||
* <em>present</em> or <em>meta-present</em> on the {@link Method} for | ||
* this descriptor. | ||
* | ||
* @param <A> the annotation type | ||
* @param annotationType the annotation type to search for; never {@code null} | ||
* @return an {@code Optional} containing the annotation; never {@code null} but | ||
* potentially empty | ||
* @see #isAnnotated(Class) | ||
* @see #findRepeatableAnnotations(Class) | ||
*/ | ||
<A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType); | ||
|
||
/** | ||
* Find all <em>repeatable</em> {@linkplain Annotation annotations} of | ||
* {@code annotationType} that are either <em>present</em> or | ||
* <em>meta-present</em> on the {@link Method} for this descriptor. | ||
* | ||
* @param <A> the annotation type | ||
* @param annotationType the repeatable annotation type to search for; never | ||
* {@code null} | ||
* @return the list of all such annotations found; neither {@code null} nor | ||
* mutable, but potentially empty | ||
* @see #isAnnotated(Class) | ||
* @see #findAnnotation(Class) | ||
* @see java.lang.annotation.Repeatable | ||
*/ | ||
<A extends Annotation> List<A> findRepeatableAnnotations(Class<A> annotationType); | ||
|
||
} |
Oops, something went wrong.