【问题标题】:Why Maven is not running test cases?为什么 Maven 不运行测试用例?
【发布时间】:2015-11-11 11:18:02
【问题描述】:

我是 maven 的初学者,我已经创建了一个 maven 项目,当我通过单击 Maven Test 执行项目时,它不会执行任何写在 @Test 注释下的测试用例。

但是当我使用 Testng 执行相同的代码时,它可以正常工作。 任何人都可以提供一些解决方案。

pom.xml:

<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>Webdriver</groupId>
  <artifactId>Webdriver</artifactId>
  <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.45.0</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
        </dependency>
    </dependencies>
    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <suiteXMLFiles>
                    <suiteXMLFile>testng.xml</suiteXMLFile>
                </suiteXMLFiles>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

【问题讨论】:

  • 你在正确的文件夹中有测试类吗? src/test/java/...
  • 这里是 testng.xml,试试 src/test/resources/testng.xml
  • @libik 是的,每个类都在 src/test/java/ 中
  • 按照惯例,测试类也必须以“Test”结尾。如果他们不这样做,您应该将&lt;includes&gt;&lt;include&gt;**/*.java&lt;/include&gt;&lt;/includes&gt; 添加到您的surefire 配置中(或类似的东西,这是来自记忆)。
  • 可能已经回答here

标签: java maven pom.xml


【解决方案1】:

按照惯例,测试类也必须以“Test”结尾。如果没有,您应该添加

<includes>
    <include>**/*.java</include>
</includes>

到你的万无一失的配置(或任何包括你的工作和你的文件命名方案)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-26
    • 2014-04-10
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多