Skip to content

Commit f71be72

Browse files
committed
Implement junit-platform-suite-engine
Implements a test engine that allows declarative execution of test suites using the `@Suite` annotation. Internally the Suite Engine uses the JUnit Platform Launcher. The engine works by mapping the `TestIdentifier` used by the launcher to `TestDescriptor` used by the engine during discovery and execution. ``` package org.junit.platform.suite; import org.junit.platform.suite.api.SelectPackages; @suite @SelectPackages("org.junit.suite.testcases") class SelectPackageSuite { } ``` Is equivalent to: ``` import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; import org.junit.platform.launcher.core.LauncherFactory; public class Main { public static void main(String[] args) { Launcher launcher = LauncherFactory.create(); LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(DiscoverySelectors.selectPackage("org.junit.suite.testcases")) .build(); launcher.execute(request); } } ``` The suite engine converts an annotated class into a discovery request. This request is executed and the resulting test plan is mapped to a tree of test descriptors. In essence the tree of test descriptors are a view on the test plan. So suppose the discovery requests produces this test plan: ``` JUnit Jupiter |- TestA ||- method1 ||- method2 |- TestB ||- method1 ||- method2 ``` Then that test plan is mapped to a tree of test descriptors like so: ``` SuiteEngine |- ExampleSuite ||-JUnit Jupiter |||- TestA ||||- method1 ||||- method2 |||- TestB ||||- method1 ||||- method2 ```` The unique identifiers are remapped by pre-pending the unique identifier of the suite. So: ``` junit-jupiter/TestA/method1() -> junit-suite/ExampleSuite/junit-jupiter/TestA/method1() ``` Issue: junit-team#744
1 parent 7a8385f commit f71be72

File tree

92 files changed

+3435
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3435
-55
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ val platformProjects by extra(listOf(
4444
project(":junit-platform-launcher"),
4545
project(":junit-platform-reporting"),
4646
project(":junit-platform-runner"),
47+
project(":junit-platform-suite"),
4748
project(":junit-platform-suite-api"),
49+
project(":junit-platform-suite-engine"),
4850
project(":junit-platform-testkit")
4951
))
5052

junit-platform-commons/src/module/org.junit.platform.commons/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
org.junit.platform.reporting,
3333
org.junit.platform.runner,
3434
org.junit.platform.suite.api,
35+
org.junit.platform.suite.engine,
3536
org.junit.platform.testkit,
3637
org.junit.vintage.engine;
3738
exports org.junit.platform.commons.support;
@@ -46,6 +47,7 @@
4647
org.junit.platform.reporting,
4748
org.junit.platform.runner,
4849
org.junit.platform.suite.api,
50+
org.junit.platform.suite.engine,
4951
org.junit.platform.testkit,
5052
org.junit.vintage.engine;
5153
}

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/EngineIdValidator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ private static boolean validateReservedIds(TestEngine testEngine) {
6161
validateWellKnownClassName(testEngine, "org.junit.vintage.engine.VintageTestEngine");
6262
return true;
6363
}
64+
if (engineId.equals("junit-platform-suite")) {
65+
validateWellKnownClassName(testEngine, "org.junit.platform.suite.engine.SuiteTestEngine");
66+
return true;
67+
}
6468
return false;
6569
}
6670

junit-platform-suite-api/junit-platform-suite-api.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99

1010
api(platform(project(":junit-bom")))
1111
api("org.apiguardian:apiguardian-api")
12+
api(project(":junit-platform-commons"))
1213

1314
osgiVerification(project(":junit-platform-commons"))
1415
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2015-2020 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.platform.suite.api;
12+
13+
import java.lang.annotation.Documented;
14+
import java.lang.annotation.ElementType;
15+
import java.lang.annotation.Inherited;
16+
import java.lang.annotation.Repeatable;
17+
import java.lang.annotation.Retention;
18+
import java.lang.annotation.RetentionPolicy;
19+
import java.lang.annotation.Target;
20+
21+
import org.apiguardian.api.API;
22+
import org.apiguardian.api.API.Status;
23+
24+
/**
25+
* {@code @Configuration} specifies the configuration {@linkplain #key key} and
26+
* {@linkplain #value value} pairs to be added to the discovery request when running
27+
* a test suite on the JUnit Platform.
28+
*
29+
* <h4>JUnit 5 Suite Support</h4>
30+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
31+
* the {@code junit-platform-suite} engine.
32+
*
33+
* @since 1.8
34+
* @see Suite
35+
* @see SelectClasses
36+
* @see SelectClasspathResource
37+
* @see SelectClasspathRoots
38+
* @see SelectDirectories
39+
* @see SelectFile
40+
* @see SelectModules
41+
* @see SelectPackages
42+
* @see SelectUris
43+
* @see IncludeClassNamePatterns
44+
* @see ExcludeClassNamePatterns
45+
* @see IncludeEngines
46+
* @see ExcludeEngines
47+
* @see IncludePackages
48+
* @see ExcludePackages
49+
* @see IncludeTags
50+
* @see ExcludeTags
51+
* @see SuiteDisplayName
52+
* @see Configuration
53+
* @see org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder#configurationParameter(String, String)
54+
*/
55+
@Retention(RetentionPolicy.RUNTIME)
56+
@Target(ElementType.TYPE)
57+
@Inherited
58+
@Documented
59+
@API(status = Status.EXPERIMENTAL, since = "1.8")
60+
@Repeatable(Configurations.class)
61+
public @interface Configuration {
62+
63+
/**
64+
* The configuration parameter key under which to add the
65+
* value to the discovery request; never {@code null} or blank.
66+
*/
67+
String key();
68+
69+
/**
70+
* The value to add to the discovery request.
71+
*/
72+
String value();
73+
74+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2015-2020 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.platform.suite.api;
12+
13+
import java.lang.annotation.Documented;
14+
import java.lang.annotation.ElementType;
15+
import java.lang.annotation.Inherited;
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
import java.lang.annotation.Target;
19+
20+
import org.apiguardian.api.API;
21+
import org.apiguardian.api.API.Status;
22+
23+
/**
24+
* {@code @Configurations} is a container for one or more
25+
* {@link Configuration @Configuration} declarations.
26+
*
27+
* <p>Note, however, that use of the {@code @Configurations} container is
28+
* completely optional since {@code @Configuration} is a
29+
* {@linkplain java.lang.annotation.Repeatable repeatable} annotation.
30+
*
31+
* <h4>JUnit 5 Suite Support</h4>
32+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
33+
* the {@code junit-platform-suite} engine.
34+
*
35+
* @since 1.8*
36+
* @see Configuration
37+
*/
38+
@Retention(RetentionPolicy.RUNTIME)
39+
@Target(ElementType.TYPE)
40+
@Inherited
41+
@Documented
42+
@API(status = Status.EXPERIMENTAL, since = "1.8")
43+
public @interface Configurations {
44+
45+
/**
46+
* An array of one or more {@link Configuration Configurations}.
47+
*/
48+
Configuration[] value();
49+
}

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/ExcludeClassNamePatterns.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,30 @@
3434
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
3535
* {@code @RunWith(JUnitPlatform.class)}.
3636
*
37+
* <h4>JUnit 5 Suite Support</h4>
38+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
39+
* the {@code junit-platform-suite} engine.
40+
*
3741
* @since 1.0
38-
* @see SuiteDisplayName
39-
* @see UseTechnicalNames
40-
* @see SelectPackages
42+
* @see Suite
4143
* @see SelectClasses
44+
* @see SelectClasspathResource
45+
* @see SelectClasspathRoots
46+
* @see SelectDirectories
47+
* @see SelectFile
48+
* @see SelectModules
49+
* @see SelectPackages
50+
* @see SelectUris
4251
* @see IncludeClassNamePatterns
52+
* @see ExcludeClassNamePatterns
53+
* @see IncludeEngines
54+
* @see ExcludeEngines
4355
* @see IncludePackages
4456
* @see ExcludePackages
4557
* @see IncludeTags
4658
* @see ExcludeTags
47-
* @see IncludeEngines
48-
* @see ExcludeEngines
59+
* @see SuiteDisplayName
60+
* @see Configuration
4961
* @see org.junit.platform.engine.discovery.ClassNameFilter#excludeClassNamePatterns
5062
* @see org.junit.platform.runner.JUnitPlatform
5163
*/

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/ExcludeEngines.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,30 @@
3030
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
3131
* {@code @RunWith(JUnitPlatform.class)}.
3232
*
33+
* <h4>JUnit 5 Suite Support</h4>
34+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
35+
* the {@code junit-platform-suite} engine.
36+
*
3337
* @since 1.0
34-
* @see SuiteDisplayName
35-
* @see UseTechnicalNames
36-
* @see SelectPackages
38+
* @see Suite
3739
* @see SelectClasses
40+
* @see SelectClasspathResource
41+
* @see SelectClasspathRoots
42+
* @see SelectDirectories
43+
* @see SelectFile
44+
* @see SelectModules
45+
* @see SelectPackages
46+
* @see SelectUris
3847
* @see IncludeClassNamePatterns
3948
* @see ExcludeClassNamePatterns
49+
* @see IncludeEngines
50+
* @see ExcludeEngines
4051
* @see IncludePackages
4152
* @see ExcludePackages
4253
* @see IncludeTags
4354
* @see ExcludeTags
44-
* @see IncludeEngines
55+
* @see SuiteDisplayName
56+
* @see Configuration
4557
* @see org.junit.platform.launcher.EngineFilter#excludeEngines
4658
* @see org.junit.platform.runner.JUnitPlatform
4759
*/

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/ExcludePackages.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,29 @@
2929
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
3030
* {@code @RunWith(JUnitPlatform.class)}.
3131
*
32+
* <h4>JUnit 5 Suite Support</h4>
33+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
34+
* the {@code junit-platform-suite} engine.
3235
* @since 1.0
33-
* @see SuiteDisplayName
34-
* @see UseTechnicalNames
35-
* @see SelectPackages
36+
* @see Suite
3637
* @see SelectClasses
38+
* @see SelectClasspathResource
39+
* @see SelectClasspathRoots
40+
* @see SelectDirectories
41+
* @see SelectFile
42+
* @see SelectModules
43+
* @see SelectPackages
44+
* @see SelectUris
3745
* @see IncludeClassNamePatterns
3846
* @see ExcludeClassNamePatterns
47+
* @see IncludeEngines
48+
* @see ExcludeEngines
3949
* @see IncludePackages
50+
* @see ExcludePackages
4051
* @see IncludeTags
4152
* @see ExcludeTags
42-
* @see IncludeEngines
43-
* @see ExcludeEngines
53+
* @see SuiteDisplayName
54+
* @see Configuration
4455
* @see org.junit.platform.runner.JUnitPlatform
4556
*/
4657
@Retention(RetentionPolicy.RUNTIME)

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/ExcludeTags.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,30 @@
5757
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
5858
* {@code @RunWith(JUnitPlatform.class)}.
5959
*
60+
* <h4>JUnit 5 Suite Support</h4>
61+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
62+
* the {@code junit-platform-suite} engine.
63+
*
6064
* @since 1.0
61-
* @see SuiteDisplayName
62-
* @see UseTechnicalNames
63-
* @see SelectPackages
65+
* @see Suite
6466
* @see SelectClasses
67+
* @see SelectClasspathResource
68+
* @see SelectClasspathRoots
69+
* @see SelectDirectories
70+
* @see SelectFile
71+
* @see SelectModules
72+
* @see SelectPackages
73+
* @see SelectUris
6574
* @see IncludeClassNamePatterns
6675
* @see ExcludeClassNamePatterns
76+
* @see IncludeEngines
77+
* @see ExcludeEngines
6778
* @see IncludePackages
6879
* @see ExcludePackages
6980
* @see IncludeTags
70-
* @see IncludeEngines
71-
* @see ExcludeEngines
81+
* @see ExcludeTags
82+
* @see SuiteDisplayName
83+
* @see Configuration
7284
* @see org.junit.platform.launcher.TagFilter#excludeTags
7385
* @see org.junit.platform.runner.JUnitPlatform
7486
*/

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/IncludeClassNamePatterns.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,30 @@
3434
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
3535
* {@code @RunWith(JUnitPlatform.class)}.
3636
*
37+
* <h4>JUnit 5 Suite Support</h4>
38+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
39+
* the {@code junit-platform-suite} engine.
40+
*
3741
* @since 1.0
38-
* @see SuiteDisplayName
39-
* @see UseTechnicalNames
40-
* @see SelectPackages
42+
* @see Suite
4143
* @see SelectClasses
44+
* @see SelectClasspathResource
45+
* @see SelectClasspathRoots
46+
* @see SelectDirectories
47+
* @see SelectFile
48+
* @see SelectModules
49+
* @see SelectPackages
50+
* @see SelectUris
51+
* @see IncludeClassNamePatterns
4252
* @see ExcludeClassNamePatterns
53+
* @see IncludeEngines
54+
* @see ExcludeEngines
4355
* @see IncludePackages
4456
* @see ExcludePackages
4557
* @see IncludeTags
4658
* @see ExcludeTags
47-
* @see IncludeEngines
48-
* @see ExcludeEngines
59+
* @see SuiteDisplayName
60+
* @see Configuration
4961
* @see org.junit.platform.engine.discovery.ClassNameFilter#STANDARD_INCLUDE_PATTERN
5062
* @see org.junit.platform.engine.discovery.ClassNameFilter#includeClassNamePatterns
5163
* @see org.junit.platform.runner.JUnitPlatform

junit-platform-suite-api/src/main/java/org/junit/platform/suite/api/IncludeEngines.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,30 @@
3030
* <p>Test suites can be run on the JUnit Platform in a JUnit 4 environment via
3131
* {@code @RunWith(JUnitPlatform.class)}.
3232
*
33+
* <h4>JUnit 5 Suite Support</h4>
34+
* <p>Test suites can be run on the JUnit Platform in a JUnit 5 environment via
35+
* the {@code junit-platform-suite} engine.
36+
*
3337
* @since 1.0
34-
* @see SuiteDisplayName
35-
* @see UseTechnicalNames
36-
* @see SelectPackages
38+
* @see Suite
3739
* @see SelectClasses
40+
* @see SelectClasspathResource
41+
* @see SelectClasspathRoots
42+
* @see SelectDirectories
43+
* @see SelectFile
44+
* @see SelectModules
45+
* @see SelectPackages
46+
* @see SelectUris
3847
* @see IncludeClassNamePatterns
3948
* @see ExcludeClassNamePatterns
49+
* @see IncludeEngines
50+
* @see ExcludeEngines
4051
* @see IncludePackages
4152
* @see ExcludePackages
4253
* @see IncludeTags
4354
* @see ExcludeTags
44-
* @see ExcludeEngines
55+
* @see SuiteDisplayName
56+
* @see Configuration
4557
* @see org.junit.platform.launcher.EngineFilter#includeEngines
4658
* @see org.junit.platform.runner.JUnitPlatform
4759
*/

0 commit comments

Comments
 (0)