如何使用pom.xml在单个类中执行测试?

时间:2013-12-26 10:13:15

标签: java maven selenium-webdriver pom.xml

我必须在一个类中执行测试。所以我将这些代码添加到我的“pom.xml”中。

 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/integration/**</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>${skipTests}</skip>
                        <excludes>
                            <exclude>**/integration/**</exclude>
                        </excludes>
                        <includes>
                            <include>**/integration/reports/**</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在集成文件夹下我有单独的文件夹。所以我需要执行报告文件夹下的测试。执行此命令时“mvn clean -Dtest = ReportTest test”。

Results :

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

如何执行测试,我需要更改pom或执行命令。

3 个答案:

答案 0 :(得分:2)

要执行测试用例(测试类),请使用maven命令(参考Maven Single Test

mvn -Dtest=com.xxx.yyy.ReportTest test - 使用完全合格的姓名而非短名称。

如果从Parent pom执行此maven命令,也有两个或多个依赖项(模块)也附加 -DfailIfNoTests = false 参数,以避免其他依赖模块上的测试失败。< / p>

答案 1 :(得分:0)

尝试从测试配置中删除它:

<excludes>
    <exclude>**/integration/**</exclude>
</excludes>

此外,使用-Dtest=ReportTest您尝试运行单个测试类ReportTest.java,而不是/reports目录中的所有测试。

答案 2 :(得分:0)

您使用类的简单名称而不是类的完全限定名称。因此,如果您在"org.testype.test.TestDemo"中进行了测试,并且这是您要运行的唯一测试,那么您的命令行将如下所示:

mvn test -Dtest=TestDemo

查看链接Maven won't run tests

相关问题