Java 未使用maven运行单元测试
我无法使用maven运行单元测试。我尝试使用mvn clean install和mvn test来运行测试,但没有提供预期的结果 我已包含以下依赖项:Java 未使用maven运行单元测试,java,maven,junit5,Java,Maven,Junit5,我无法使用maven运行单元测试。我尝试使用mvn clean install和mvn test来运行测试,但没有提供预期的结果 我已包含以下依赖项: <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams-test-utils</artifactId>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<!--include manifest in repository jar-->
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
方法名称如下注释和名称所示:
@Test
void testMethodName() throws Exception {
我能够在Intellij中获得预期的结果,但maven没有运行测试
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ truckmsg-processor ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
您的系统是否可能没有正确注入正确的类 在某些项目中检查我的代码时,我注意到我有以下符号:
@RunWith(SpringJUnit4ClassRunner.class)
您可以看到它的功能。更改junit Jupiter依赖项有助于:
@SpringBootTest(classes = App.class)
@WebAppConfiguration
@Transactional
public class BulkTests {
@Test
public void test1() {
}
}
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
org.junit.jupiter
朱尼特朱庇特
测试
添加此依赖项有助于:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
org.junit.vintage
朱尼特老式发动机
测试
org.hamcrest
汉克雷斯特岩芯
您必须提供更多信息。例如maven错误输出。您是运行maven命令mvnclean包还是mvnclean包install@michalk:Stackoverflow不允许我在开始时添加代码。我添加了必要的内容details@Sambit:是的,我做了maven清洁安装。谢谢你现在运行测试用例了吗?我想OP想要使用JUnit5。为什么他会把他的版本降到4级?@UrbanoJVR:添加了建议的依赖项。这没有帮助。谢谢是的,致命的错误。您正在使用junit jupyter api,我发布junit。您是否尝试过添加Jupyter API版本5.5.0-M1标记?(我认为它不起作用,但可以证明)
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>