只有在使用Maven运行测试用例时,TestNG测试结果控制台才为空(测试)

时间:2016-10-12 10:32:24

标签: eclipse maven selenium testng pom.xml

我为自动化selenium脚本创建了一个maven项目,并将所有必需的依赖项添加到pom.xml中。 如果我执行maven构建(测试),我在TestNG.xml中提到的测试用例运行正常。但是TestNG测试结果控制台是空白的。它没有说出有多少案件被执行以及通过多少案件的任何信息?虽然Eclipse控制台输出具有测试状态。

TestNG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" name="Default suite" >
  <test verbose="2" name="Default test" >
    <classes >
      <class name="automation.BrowserNavigation"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->
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>TupasRegression</groupId>
  <artifactId>TupasRegression</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>

      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>src/TestNG.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>
    </plugins>

  </build>

  <profiles>

</profiles>
<dependencies>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.0</version>
</dependency>
  <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>
           <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi-examples</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>
               <dependency>
              <groupId>org.apache.poi</groupId>
              <artifactId>poi-excelant</artifactId>
              <version>3.14</version>
              <scope>compile</scope>
           </dependency>



          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-ooxml-schemas</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>
          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>poi-scratchpad</artifactId>
                 <version>3.14</version>
                 <scope>compile</scope>
          </dependency>




<!-- </dependency> -->


          <dependency>
                 <groupId>org.apache.poi</groupId>
                 <artifactId>openxml4j</artifactId>
                 <version>1.0-beta</version>
          </dependency>

     <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.3.1</version>
        </dependency>


</dependencies>
</project>

Eclipse Console Output TestNG result page

3 个答案:

答案 0 :(得分:1)

您在屏幕截图中显示的testng控制台不会显示任何结果 - 这是一个testng插件提供的控制台,如果您选择使用Run As运行测试或套件,它只会显示结果 - > TestNG(套件/测试)选项。

当您在maven中运行时,testng插件不会被执行,因此您在控制台中看不到任何内容。如果您需要此运行的结果,则需要检查maven生成的目标文件夹中的test-results文件夹。

答案 1 :(得分:0)

我遇到了同样的问题。我认为我的答案不是修复它的方法,但是您可以通过在浏览器上运行它来查看已执行的案例数量以及index.html中传递的数量,此文件位于test-output文件夹中。每次运行测试用例时,TestNG都会更新此文件。

答案 2 :(得分:0)

可以在Maven构建控制台输出中显示测试结果。

1)创建一个testng.xml文件,该文件概述了您的测试类。

要在eclipse中执行操作,请右键单击您的maven项目,然后选择TESTNG&gt;转换为TestNG。

2)更新Maven POM文件以包含相关的依赖项和插件。 关键配置是Maven surefire插件,它配置为指向您的testng.xml文件。

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</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>
</dependencies>

<build>
    <plugins>
        <!-- Following plugin executes the testng tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.14.1</version>
            <configuration>
                <!-- Suite testng xml file to consider for test execution -->
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>

                </suiteXmlFiles>
            </configuration>
        </plugin>
        <!-- Compiler plugin configures the java version to be usedfor compiling 
            the code -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>

3)运行Maven测试,TestNG结果将出现在Maven输出控制台中。