-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce named argument set support for @ParameterizedTest
Running ArgumentSetDemo, results in the following output: [1] Important Files [2] Other Files Important Files :: path1, path2 Other Files :: path3, path4 [1] Mixed Arguments Types :: Important Files [2] Mixed Arguments Types :: file1=path3, file2=path4 Closes #3818
- Loading branch information
Showing
7 changed files
with
360 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2015-2024 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 example; | ||
|
||
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; | ||
import static org.junit.jupiter.params.provider.Arguments.argumentSet; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.FieldSource; | ||
|
||
@Execution(SAME_THREAD) | ||
class ArgumentSetDemo { | ||
|
||
@BeforeEach | ||
void printDisplayName(TestInfo testInfo) { | ||
System.out.println(testInfo.getDisplayName()); | ||
} | ||
|
||
@ParameterizedTest | ||
@FieldSource("argumentSets") | ||
void defaultArgumentSetDisplayName(File file1, File file2) { | ||
} | ||
|
||
@ParameterizedTest(name = "{argumentSetName} :: {arguments}") | ||
@FieldSource("argumentSets") | ||
void customArgumentSetNameAndArgumentsDisplayName(File file1, File file2) { | ||
} | ||
|
||
@DisplayName("Mixed Arguments Types") | ||
@ParameterizedTest(name = "[{index}] {displayName} :: {argumentSetNameOrArgumentsWithNames}") | ||
@FieldSource("mixedArgumentsTypes") | ||
void mixedArgumentsTypesDisplayName(File file1, File file2) { | ||
} | ||
|
||
// @formatter:off | ||
static List<Arguments> argumentSets = Arrays.asList( | ||
argumentSet("Important Files", new File("path1"), new File("path2")), | ||
argumentSet("Other Files", new File("path3"), new File("path4")) | ||
); | ||
// @formatter:on | ||
|
||
// @formatter:off | ||
static List<Arguments> mixedArgumentsTypes = Arrays.asList( | ||
argumentSet("Important Files", new File("path1"), new File("path2")), | ||
arguments(new File("path3"), new File("path4")) | ||
); | ||
// @formatter:on | ||
|
||
} |
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.