如何使用maven运行基于junit4的一致性测试?

时间:2013-02-01 15:01:57

标签: maven concordion

我的pom.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.demo.DemoTestSteps</groupId>
<artifactId>DemoTestSteps</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.11</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                </includes>
                <systemPropertyVariables>
                    <propertyName>concordion.output.dir</propertyName>
                    <buildDirectory>target/concordion</buildDirectory>
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.concordion</groupId>
        <artifactId>concordion</artifactId>
        <version>1.4.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

这是我的考试班:

package application;

import org.concordion.integration.junit3.ConcordionTestCase;

public class Application extends ConcordionTestCase {
    public void runTest() {
    } 
}

因此,当我使用mvn clean test运行测试时,将执行测试。但是,如果我稍微修改一下测试类,那么它使用juni4,运行上一个命令就不会执行任何操作。

package application;

import org.concordion.integration.junit4.ConcordionRunner;

@RunWith(ConcordionRunner.class)
public class Application {
    public void runTest() {
    } 
}

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.412 sec

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Fri Feb 01 16:58:18 EET 2013
[INFO] Final Memory: 26M/62M
[INFO] ------------------------------------------------------------------------

有谁知道如何克服这个问题?

1 个答案:

答案 0 :(得分:2)

我刚尝试使用你的pom.xml和java类,它对我有用。

我确实需要修复JUnit 4案例中缺少的RunWith导入。你可能想检查为什么你没有得到编译错误?

正在使用的版本:

  • Apache Maven 3.0.4(r1232337; 2012-01-17 21:44:56 + 1300)
  • Java版本:1.6.0_30,供应商:Sun Microsystems Inc.