简体   繁体   English

Maven 项目:能够单独运行测试,但无法使用 Maven 测试运行整个项目 - 0 场景 0 步骤问题

[英]Maven project: able to run test seperately but unable to run whole project with Maven tests - 0 scenario 0 steps issue

When I run Maven build using pom.xml to call testng.xml I encounter 0 scenario and 0 steps 0m0.000s issue. When I run Maven build using pom.xml to call testng.xml I encounter 0 scenario and 0 steps 0m0.000s issue. Anyone can help me?任何人都可以帮助我吗? Thanks!谢谢!

The command to execute Maven build:执行 Maven 构建的命令:

mvn clean test -Dsurefire.suiteXmlFiles="C:\Users\User\eclipse-workspace\project\src\test\resources\testng.xml"

The code works fine when I run the tests separately with testrunner.class or testng.xml .当我使用testrunner.classtestng.xml单独运行测试时,代码工作正常。 But unable to run the whole project with Maven test.但无法通过 Maven 测试运行整个项目。

File directory文件目录

项目文件目录点击这里

pom.xml 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>project</groupId>
  <artifactId>project</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>project</name>
  <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
        <build>
      <plugins>
<plugin>
           <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>        
            </plugin>
            <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-resources-plugin -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
</plugin> 
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
           <version>3.0.0-M5</version>
            <configuration>
               <suiteXmlFiles>
               <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
            <!--  <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> -->
               </suiteXmlFiles>      
        <testFailureIgnore>true</testFailureIgnore>
            </configuration>
         </plugin>
      </plugins>
   </build>    
 <repositories>
      <repository>
         <id>jcenter</id>
         <name>bintray</name>
         <url>http://jcenter.bintray.com</url>
      </repository>
   </repositories>
   <dependencies>
      <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
      <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-jvm-deps</artifactId>
         <version>1.0.6</version>
      </dependency>
      <dependency>
         <groupId>net.masterthought</groupId>
         <artifactId>cucumber-reporting</artifactId>
         <version>1.0.0</version>
      </dependency>
      <!--      <dependency> -->
      <!--          <groupId>io.cucumber</groupId> -->
      <!--          <artifactId>gherkin</artifactId> -->
      <!--          <version>4.1.3</version> -->
      <!--      </dependency> -->
      <!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>gherkin</artifactId>
         <version>2.12.2</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>cucumber-testng</artifactId>
         <version>1.2.5</version>
         <scope>compile</scope>
         <exclusions>
            <exclusion>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
            </exclusion>
         </exclusions>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
      <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-picocontainer</artifactId>
         <version>2.4.0</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
      <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-html</artifactId>
         <version>0.2.7</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/net.sourceforge.cobertura/cobertura -->
      <dependency>
         <groupId>net.sourceforge.cobertura</groupId>
         <artifactId>cobertura</artifactId>
         <version>1.9.4.1</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
      <dependency>
         <groupId>org.hamcrest</groupId>
         <artifactId>hamcrest-core</artifactId>
         <version>1.3</version>
      </dependency>
      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.10</version>
    <!--      <scope>test</scope> -->
      </dependency>
  <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.28.0</version>
    </dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>2.0.0</version>
</dependency>     
<!--  <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency> -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>5.0.0-BETA6</version>
        </dependency>
        <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
 </dependency> 
    <!-- For Cucumber -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <!-- <scope>test</scope> -->
        </dependency>
 
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <!-- <scope>test</scope> -->
        </dependency>
 
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <!-- <scope>test</scope> -->
        </dependency>
 
        <!-- For dependency Injection -->
 
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <!-- <scope>test</scope> -->
        </dependency>
  
        <!-- For Extent Reports -->
        <!-- Extent Report Adapter for Cucumber -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports-cucumber4-adapter</artifactId>
            <version>1.0.6</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.1.2</version>
        </dependency>
 
 
        <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>
 
        <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.10.2</version>
        </dependency>
        
        <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-gherkin</artifactId>
    <version>5.6.0</version>
</dependency>
<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version>
</dependency>
<dependency>
 <groupId>com.vimalselvam</groupId>
 <artifactId>cucumber-extentsreport</artifactId>
 <version>3.0.2</version>
</dependency>  
   </dependencies>

</project>

testng.xml testng.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="1" parallel="tests" thread-count="1" configfailurepolicy="continue">
  <test name="Test" annotations="JDK" preserve-order="true">
    <classes>
     <class name="Cucumber.testRunner"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

testrunner.java testrunner.java

@CucumberOptions(
    features="src/test/java/feature/",
    glue= {"teststeps"},
    format = {"pretty","html:target/cucumber-reports/cucumber-pretty","json:target/cucumber-reports/CucumberTestReport.json", "rerun:target/cucumber-reports/rerun.txt"},
    plugin = {"json:target/cucumber-reports/CucumberTestReport.json"}
    )
    
    public class testRunner {
        private TestNGCucumberRunner testNGCucumberRunner;
        
        @BeforeClass(alwaysRun = true)
        public void setupclass() throws Exception {
            testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
        }
        
        @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider ="feature")
        public void feature(CucumberFeatureWrapper cucumberFeature) {
            testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
        }
        
        @DataProvider(name="feature")
        public Object[][] getFeatures()
        {
            if(testNGCucumberRunner == null){
                testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
            }
            return testNGCucumberRunner.provideFeatures();
        }
        
        @AfterClass(alwaysRun = true)
        public void teardownclass() throws Exception{
            testNGCucumberRunner.finish();
        }
    }

Maven build issue Maven 构建问题

[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
Feature: test property feature

  Scenario Outline: Customer checks the value of housing property # zooproperty.feature:3
    Given acustomer on the home page
    When aI type search "<propertysearch>"
    And aI click on submit
    Then aI see the properties value

    Examples: 

0 Scenarios
0 Steps
0m0.000s

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.114 s <<< FAILURE! - in TestSuite
[ERROR] Cucumber.testRunner.feature[test property feature](1)  Time elapsed: 0.09 s  <<< FAILURE!
java.lang.AbstractMethodError: cucumber.runtime.java.JavaStepDefinition.matchedArguments(Lgherkin/formatter/model/Step;)Ljava/util/List;
    at Cucumber.testRunner.feature(testRunner.java:44)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   testRunner.feature:44 » AbstractMethod cucumber.runtime.java.JavaStepDefinitio...
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] 
[ERROR] There are test failures.

Please refer to C:\Users\User\Desktop\project\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.882 s
[INFO] Finished at: 2020-08-06T22:12:28+08:00
[INFO] ------------------------------------------------------------------------

Try running this please:请尝试运行:

mvn clean test -DsuiteXmlFiles=C:\Users\User\eclipse-workspace\project\src\test\resources\testng.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM