============================================ --------------------------- --------------------- <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency> import org.junit.jupiter.api.Test; public class MyTest { @Test void test1() { } @Test void test2() { } } <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin> </plugins> </build> mvn test ---------------------------- import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; public class MyTest { @ParameterizedTest @ValueSource(ints = {1, 2, 3}) void test(int number) { } } import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.TestTemplateInvocationContext; import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; @ExtendWith(MyCustomExtension.class) public class MyTestTemplate { @TestTemplate @ExtendWith(MyCustomExtension.class) void testTemplate(String name) { } static class MyCustomExtension implements TestTemplateInvocationContextProvider { @Override public boolean supportsTestTemplate(ExtensionContext context) { return true; } @Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { } } } ------ ------------------ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; public class MyTest { @Test void test1() { } @Test void test2() { } @ParameterizedTest @ValueSource(ints = {1, 2, 3}) void test(int number) { } static class MyCustomExtension implements TestTemplateInvocationContextProvider { @Override public boolean supportsTestTemplate(ExtensionContext context) { return true; } @Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { } } } <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.2</version> <scope>test</scope> </dependency> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> </plugin> </plugins> </build> - [JUnit 5 User Guide - Writing Tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests) - [JUnit 5 User Guide - Extensions](https://junit.org/junit5/docs/current/user-guide/#extensions)


上一篇:
下一篇:
切换中文