Search code examples
javamaventestngpom.xml

cannot run tests using maven to run my projects


I am trying to run my tests but I am facing an issue where I cannot run my tests when I run the following command: mvn clean test

my project contain 3 modules (see image attached): enter image description here

Every module in the project contains pom.xml file which contains only the dependencies relevant for the module.

the main pom.xml (the reactor) is the file which run the test and control the project, and this is its content:

<?xml version="1.0" encoding="UTF-8"?>

<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>com.hackeruso</groupId>
  <artifactId>neo</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <modules>
      <module>automation-ui</module>
      <module>automation-api</module>
      <module>morpheus</module>
    </modules>

    <name>neo</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <aspectj.version>1.8.10</aspectj.version>
      <testng.version>7.3.0</testng.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.qameta.allure</groupId>
      <artifactId>allure-testng</artifactId>
      <version>2.13.6</version>
    </dependency>
      <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>${testng.version}</version>
          <scope>test</scope>
      </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20</version>
          <configuration>
            <argLine>
              -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
            </argLine>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>org.aspectj</groupId>
              <artifactId>aspectjweaver</artifactId>
              <version>${aspectj.version}</version>
            </dependency>
          </dependencies>
        </plugin>

      </plugins>
    </pluginManagement>
  </build>
</project>

when I run the command mvn test I am getting the following message:

No tests to run.

And this image shows where I hold my tests: enter image description here

src/test/java/com/hackeruso/automation/ui/LoginTest

This is an example for my test class: --------------------EDIT-------------------------------------------

package com.hackeruso.automation.ui;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class LoginTest extends BaseTest{

    @Test(dataProvider = "userDetailsProvider")
    public void loginTest(String username, String password){
        signIn(username, password);
    }

    @DataProvider(name = "userDetailsProvider")
    public Object[][] userDetailsProvider(){
        return new Object[][] {
                {"[email protected]", "*******"}
        };
    }

}

Solution

  • The parent project has a packaging of <packaging>pom</packaging>. This means this is a meta-project and should not contain any source code.

    What you need to do is to move the tests in any of the existing modules or create a new one for these tests. By looking at the package structure of the tests, I guess it would be automation-ui in your case.

    Then use the following command to run the tests from all the modules

    mvn test -am
    

    Where -am will make all the submodules.

    If you want to run tests for a single module, use

    mvn test -pl <submodule-name>