在我的Spring应用程序中,我正确地命名了测试:
SRC -主要 -测试 -java -com.mypackage.sth -utils SomethingTest.java我可以直接从IDE intellij运行它,…
首先,在构建标记之外提取Junit 的 依赖 强>
然后添加这些行来构建
<sourceDirectory>src/main/{PATH TO SRC}</sourceDirectory> <testSourceDirectory>src/test/{PATH TO TESTS}</testSourceDirectory>
应该看起来像这样
<project> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <sourceDirectory>src/main/{PATH TO SRC}</sourceDirectory> <testSourceDirectory>src/test/{PATH TO TESTS}</testSourceDirectory> <plugins> <!-- JUnit 5 requires Surefire version 2.22.0 or higher --> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.0</version> </plugin> </plugins> </build> </project>