4

我正在使用 Maven 3.0.3、JUnit 4.8.1 和 Spring 3.1.1.RELEASE。我以这种方式配置了我的 Surefire 插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.14.1</version>
    <configuration>
        <reuseForks>false</reuseForks>
        <argLine>-Xmx2048m -XX:MaxPermSize=512M</argLine>
    </configuration>
</plugin>

我注意到当我的单元测试由于 IllegalStateExceptions 而失败时,Maven 永远不会打印出在执行结束时失败的测试名称。相反,我会看到

mvn clean install
...
Tests in error:
? IllegalState Failed to load ApplicationContext
? IllegalState Failed to load ApplicationContext
? IllegalState Failed to load ApplicationContext
? IllegalState Failed to load ApplicationContext

如何让 Mavne 打印出有关测试失败的更具体信息?现在,我必须深入研究 surefire-reports 目录以找出失败的原因。我的大多数 JUnit 测试如下所示:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml" })
public class CleverTeacherServiceTest extends AbstractImportServiceTest
{
4

1 回答 1

1

我认为您的 Spring 测试配置在您的测试运行之前失败。您通常应该会在控制台中看到失败的测试,例如:


测试

运行 TestSuite .. 测试运行:234,失败:1,错误:0,跳过:0,经过时间:7.019 秒 <<< 失败!fooTest(BarTest) 已用时间:0.011 秒 <<< 失败!fooTest(BarTest.java:23)

结果 :

测试失败:BarTest.fooTest:23 null

测试运行:234,失败:1,错误:0,跳过:0

您可以运行您的测试,设置 surefire 插件属性useFile== false 以将所有插件输出发送到控制台。我不会在 pom 文件中配置它,而是像这样运行它:

mvn -Dsurefire.useFile=false clean test

有关配置信息,请参阅Surefire 插件文档

于 2013-07-16T23:14:38.797 回答