Skip to content

Commit 5b942d5

Browse files
committed
ConsoleLauncher options for conf param resource
1 parent b09cded commit 5b942d5

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

documentation/src/docs/asciidoc/user-guide/advanced-topics/junit-platform-reporting.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,12 @@ $ java -jar junit-platform-console-standalone-{platform-version}.jar <OPTIONS> \
136136
--config=junit.platform.reporting.open.xml.enabled=true \
137137
--config=junit.platform.reporting.output.dir=reports
138138
----
139+
140+
Configuration parameters can also be set via a resource path file, by specifying the
141+
`--config-resource` option:
142+
143+
[source,console,subs=attributes+]
144+
----
145+
$ java -jar junit-platform-console-standalone-{platform-version}.jar <OPTIONS> \
146+
--config-resource=configuration.properties
147+
----

junit-platform-console/src/main/java/org/junit/platform/console/options/TestDiscoveryOptionsMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ static class RuntimeConfigurationOptions {
260260
// Implementation note: the @Option annotation is on a setter method to allow validation.
261261
private final Map<String, String> configurationParameters = new LinkedHashMap<>();
262262

263+
@Option(names = {
264+
"--config-resource" }, paramLabel = "PATH", arity = "1", description = "Set configuration parameters for test discovery and execution, from a resource file. This option can be repeated.")
265+
private List<String> configurationParametersResources = new ArrayList<>();
266+
267+
@Option(names = { "-config-resource" }, arity = "1", hidden = true)
268+
private List<String> configurationParametersResources2 = new ArrayList<>();
269+
263270
@CommandLine.Spec
264271
private CommandLine.Model.CommandSpec spec;
265272

@@ -296,6 +303,8 @@ private void validateUnique(String key, String newValue) {
296303

297304
private void applyTo(TestDiscoveryOptions result) {
298305
result.setAdditionalClasspathEntries(merge(additionalClasspathEntries, additionalClasspathEntries2));
306+
result.setConfigurationParametersResources(
307+
merge(configurationParametersResources, configurationParametersResources2));
299308
result.setConfigurationParameters(configurationParameters);
300309
}
301310
}

platform-tests/src/test/java/org/junit/platform/console/options/CommandLineOptionsParsingTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,33 @@ void parseValidConfigurationParameters(ArgsType type) {
538538
// @formatter:on
539539
}
540540

541+
@ParameterizedTest
542+
@EnumSource
543+
void parseValidConfigurationParametersResource(ArgsType type) {
544+
// @formatter:off
545+
assertAll(
546+
() -> assertThat(type.parseArgLine("-config-resource foo.properties").discovery.getConfigurationParametersResources())
547+
.containsOnly("foo.properties"),
548+
() -> assertThat(type.parseArgLine("--config-resource foo.properties").discovery.getConfigurationParametersResources())
549+
.containsOnly("foo.properties"),
550+
() -> assertThat(type.parseArgLine("-config-resource foo.properties -config-resource bar.properties").discovery.getConfigurationParametersResources())
551+
.containsExactly("foo.properties", "bar.properties"),
552+
() -> assertThat(type.parseArgLine("--config-resource foo.properties --config-resource bar.properties").discovery.getConfigurationParametersResources())
553+
.containsExactly("foo.properties", "bar.properties")
554+
);
555+
// @formatter:on
556+
}
557+
541558
@Test
542559
void parseInvalidConfigurationParameters() {
543560
assertOptionWithMissingRequiredArgumentThrowsException("-config", "--config");
544561
}
545562

563+
@Test
564+
void parseInvalidConfigurationParametersResource() {
565+
assertOptionWithMissingRequiredArgumentThrowsException("-config-resource", "--config-resource");
566+
}
567+
546568
@ParameterizedTest
547569
@EnumSource
548570
void parseInvalidConfigurationParametersWithDuplicateKey(ArgsType type) {

0 commit comments

Comments
 (0)