gpt4 book ai didi

使用 Maven 运行时跳过 Spring 测试

转载 作者:行者123 更新时间:2023-11-28 20:04:03 30 4
gpt4 key购买 nike

我正尝试在 Maven 构建或安装的 spring 项目上运行 JUnit 测试。

src/main/test 中的测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:mvc-dispatcher-servlet.xml",
"classpath:appContext.xml",
"classpath:databaseContext.xml"})
public class Test {
@Autowired
private EventService evtService;

@org.junit.Test
public void test1(){
List<String> eventNames = evtService.getEventNames();
Assert.assertTrue(eventNames.size() > 0);
}
}

在 POM 中:

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>

当我使用 Run as -> JUnit 测试从 eclipse 运行测试类时它工作正常,但是当我运行 Maven Install 例如我得到:

 T E S T S
-------------------------------------------------------
Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=10, useUnlimitedThreads=false
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

版本:JUnit:4.11; Spring :3.2.3.RELEASE

最佳答案

如果你在你的问题中提到的是正确的 The test class in src/main/test 这就是一个简单的问题,因为测试必须位于 /src/test/java 代替。

关于使用 Maven 运行时跳过 Spring 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18811561/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com