forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allowing selecting methods by name in test suites
This commit adds a new `@SelectMethod` annotation and a corresponding `@SelectMethods` container annotation. The annotation can be used to specify a method to select when running a test suite on the JUnit Platform. These annotations allow users to selectively run certain test methods within a test class, which can be useful for large test suites with many methods. The `@SelectMethod annotation` specifies the class and name of the method to select, as well as the parameter types of the method if applicable. In addition to adding these new classes, three test cases have been added to demonstrate their usage. These test cases cover scenarios such as selecting a test method with no parameters, selecting a test method with parameters, and using the @SelectMethods container to specify multiple test methods to run. Closes junit-team#3303. Resolves junit-team#3012. Co-authored-by: Marc Philipp <mail@marcphilipp.de>
- Loading branch information
1 parent
71c2381
commit 39cf2d5
Showing
8 changed files
with
246 additions
and
1 deletion.
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
87 changes: 87 additions & 0 deletions
87
junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/SelectMethod.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,87 @@ | ||
/* | ||
* Copyright 2015-2023 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 | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.suite.api; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code @SelectMethod} is a {@linkplain Repeatable repeatable} annotation that | ||
* specifies a method to <em>select</em> when running a test suite on the JUnit | ||
* Platform. | ||
* | ||
* @since 1.10 | ||
* @see Suite | ||
* @see org.junit.platform.runner.JUnitPlatform | ||
* @see org.junit.platform.engine.discovery.DiscoverySelectors#selectMethod(Class, String, String) | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Inherited | ||
@Documented | ||
@API(status = EXPERIMENTAL, since = "1.10") | ||
@Repeatable(SelectMethods.class) | ||
public @interface SelectMethod { | ||
|
||
/** | ||
* The class in which the method is declared, or a subclass thereof. | ||
*/ | ||
Class<?> clazz(); | ||
|
||
/** | ||
* The name of the method to select; never blank. | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* The parameter types of the method to select. | ||
* | ||
* <p>This is typically a comma-separated list of atomic types, fully | ||
* qualified class names, or array types; however, the exact syntax | ||
* depends on the underlying test engine. | ||
* | ||
* <p>If the method takes no parameters, this attribute must be an | ||
* empty string. | ||
* | ||
* <p>Array parameter types may be specified using either the JVM's internal | ||
* String representation (e.g., {@code [[I} for {@code int[][]}, | ||
* {@code [Ljava.lang.String;} for {@code java.lang.String[]}, etc.) or | ||
* <em>source code syntax</em> (e.g., {@code int[][]}, {@code java.lang.String[]}, | ||
* etc.). | ||
* <p> | ||
* <table class="plain"> | ||
* <caption>Examples</caption> | ||
* <tr><th>Method</th><th>Parameter types list</th></tr> | ||
* <tr><td>{@code java.lang.String.chars()}</td><td>The empty string</td></tr> | ||
* <tr><td>{@code java.lang.String.equalsIgnoreCase(String)}</td><td>{@code java.lang.String}</td></tr> | ||
* <tr><td>{@code java.lang.String.substring(int, int)}</td><td>{@code int, int}</td></tr> | ||
* <tr><td>{@code example.Calc.avg(int[])}</td><td>{@code [I}</td></tr> | ||
* <tr><td>{@code example.Calc.avg(int[])}</td><td>{@code int[]}</td></tr> | ||
* <tr><td>{@code example.Matrix.multiply(double[][])}</td><td>{@code [[D}</td></tr> | ||
* <tr><td>{@code example.Matrix.multiply(double[][])}</td><td>{@code double[][]}</td></tr> | ||
* <tr><td>{@code example.Service.process(String[])}</td><td>{@code [Ljava.lang.String;}</td></tr> | ||
* <tr><td>{@code example.Service.process(String[])}</td><td>{@code java.lang.String[]}</td></tr> | ||
* <tr><td>{@code example.Service.process(String[][])}</td><td>{@code [[Ljava.lang.String;}</td></tr> | ||
* <tr><td>{@code example.Service.process(String[][])}</td><td>{@code java.lang.String[][]}</td></tr> | ||
* </table> | ||
*/ | ||
String parameters() default ""; | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/SelectMethods.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,47 @@ | ||
/* | ||
* Copyright 2015-2023 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 | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.suite.api; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
/** | ||
* {@code @SelectMethods} is a container for one or more | ||
* {@link SelectMethod @SelectMethod} declarations. | ||
* | ||
* <p>Note, however, that use of the {@code @SelectMethods} container is | ||
* completely optional since {@code @SelectMethod} is a | ||
* {@linkplain java.lang.annotation.Repeatable repeatable} annotation. | ||
* | ||
* @since 1.10 | ||
* @see SelectMethod | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Inherited | ||
@Documented | ||
@API(status = EXPERIMENTAL, since = "1.10") | ||
public @interface SelectMethods { | ||
|
||
/** | ||
* An array of one or more {@link SelectMethod @SelectMethod} declarations. | ||
*/ | ||
SelectMethod[] value(); | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
...rm-tests/src/test/java/org/junit/platform/suite/engine/testsuites/SelectMethodsSuite.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,23 @@ | ||
/* | ||
* Copyright 2015-2023 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 | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.suite.engine.testsuites; | ||
|
||
import org.junit.platform.suite.api.SelectMethod; | ||
import org.junit.platform.suite.api.Suite; | ||
import org.junit.platform.suite.engine.testcases.MultipleTestsTestCase; | ||
|
||
/** | ||
* @since 1.10 | ||
*/ | ||
@Suite | ||
@SelectMethod(clazz = MultipleTestsTestCase.class, name = "test") | ||
public class SelectMethodsSuite { | ||
} |