简体   繁体   中英

Maven tests not running when executed from command line

I am trying to run one project from the command line using mvn test command. It shows build success but not running any tests. I am using TestNG. Console output:

在此处输入图像描述

I have tried all the suggestions provided in StackOverflow but still, it's not running. I don't have surefire plugin as well. Please let me know what I am missing here.

Here is my 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

Here is my XML file

<?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:

  1. AddMaven-compiler-plugin : Compiler-plugin is used to compile the sources of our project

     <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 .

     <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. Replace your testng.xml file relative path here. 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 .

So the topic should be named "Where the testng.xml ought to be".

If the config says testng.xml then the Suite XML should be at:

/testng.xml

the same directory where the POM is located - /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 , where the "/" is the CWD - exactly the directory where the pom.xml is placed and then src/test/resources are sub-directories.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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