简体   繁体   English

从命令行执行时 Maven 测试未运行

[英]Maven tests not running when executed from command line

I am trying to run one project from the command line using mvn test command.我正在尝试使用mvn test命令从命令行运行一个项目。 It shows build success but not running any tests.它显示构建成功但未运行任何测试。 I am using TestNG.我正在使用 TestNG。 Console output:控制台 output:

在此处输入图像描述

I have tried all the suggestions provided in StackOverflow but still, it's not running.我已经尝试了 StackOverflow 中提供的所有建议,但仍然没有运行。 I don't have surefire plugin as well.我也没有万能插件。 Please let me know what I am missing here.请让我知道我在这里缺少什么。

Here is my 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.way2automation.www</groupId>
    <artifactId>SecondMavenTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.19</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.2.3</version>
        </dependency>

        <!-- POI JARS STARTS -->

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.1</version>
        </dependency>

        <!-- POI JARS ENDS -->


    </dependencies>
</project>

maven cmd screenshot maven cmd 截图

Here is my XML file这是我的 XML 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestNG Suite">


    <listeners>
        <listener class-name="customListeners.CustomListeners"></listener>
        <listener class-name="org.uncommons.reportng.HTMLReporter"></listener>
    </listeners>


    <test name="BankManagerLogin">
        <classes>
            <class name="testcases.BankManagerLogin" />
        </classes>
    </test>
    
    <test name=" AddCustomerLogin ">
        <classes>
            <class name="testcases.AddCustomerLogin" />
        </classes>
    </test>
    
        <test name=" OpenAccount">
        <classes>
            <class name="testcases.OpenAccount" />
        </classes>
    </test>
    

    
</suite> <!-- Suite -->

Need to configure below plugins in order to run test using maven:需要配置以下插件才能使用 maven 运行测试:

  1. AddMaven-compiler-plugin : Compiler-plugin is used to compile the sources of our project添加Maven-compiler-plugin : Compiler-plugin 用于编译我们项目的源代码

     <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerVersion>3.5.1</compilerVersion> <source>8</source> <target>8</target> </configuration> </plugin>
  2. Add Maven-surefire-plugin : Surefire-plugin is responsible for running tests that are placed in test source directory /src/test/java .添加Maven-surefire-plugin : Surefire-plugin 负责运行放置在测试源目录/src/test/java中的测试。

     <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin>

Both plugin should be under <plugins> tag.两个插件都应该在<plugins>标签下。 Replace your testng.xml file relative path here.在此处替换您的testng.xml文件相对路径。 eg A folder name config created under your project and placed the testng.xml file, then xml path would be config/testng.xml . eg A folder name config created under your project and placed the testng.xml file, then xml path would be config/testng.xml .

The fix is very natural!修复非常自然!

You are in current dir CWD , your POM is located in /pom.xml , you run mvn test , and your configuration says testng.xml .您在当前目录CWD中,您的 POM 位于/pom.xml中,您运行mvn test ,您的配置显示 testng.Z0F635D0E0F3874FFF8B7581C132E67C

So the topic should be named "Where the testng.xml ought to be".所以主题应该命名为“testng.xml 应该在哪里”。

If the config says testng.xml then the Suite XML should be at:如果配置显示 testng.xml则套件 XML 应位于:

/testng.xml /testng.xml

the same directory where the POM is located - /pom.xml POM 所在的同一目录 - /pom.xml

But if you configure src/test/resources/testng.xml , then the real location of the TestNG Suite XML would be:但是,如果您配置src/test/resources/testng.xml ,那么 TestNG Suite XML 的实际位置将是:

/src/test/resources/testng.xml , where the "/" is the CWD - exactly the directory where the pom.xml is placed and then src/test/resources are sub-directories. /src/test/resources/testng.xml ,其中“/”是 CWD - 正是放置 pom.xml 的目录,然后src/test/resources是子目录。

Please read the documentation!请阅读文档!

Especially see this part in the documentation:特别是在文档中看到这部分:

      <suiteXmlFiles>
        <file>src/test/resources/testng1.xml</file>
        <file>src/test/resources/testng2.xml</file>
      </suiteXmlFiles>

https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html#Running_Tests_in_Parallel https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html#Running_Tests_in_Parallel

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

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