Search code examples
javamaventestingtestngmulti-module

How to execute a TestNG test case outside a project, using Maven Multi module


I am working on a multi module maven project.

My Project Structure is as below -

Parent-Module (Packaging - pom)
BaseFramework (Packaging - jar)
TestProject (Packaging - jar) (Added BaseFramework as a dependency in pom.xml of the project)
TestRunner (Packaging - jar) (Added BaseFramework and TestProject as a dependency in pom.xml of the project)

TestProject has a testNG.xml file which executes the test cases of the specified class. Test cases uses Data providers and path is mentioned as relative path (./src/main/resources/pmRolDetailsWithId.xml)

TestRunner project has a Suite Runner file (lets say SuiteRunner.xml) Which contains the path of testNG.xml from (TestProject).

When executed, the test tries to find the "pmRolDetailsWithId.xml" file in TestRunner Project. Path - /TestRunner/src/main/resources/pmRolDetailsWithId.xml and the file is not found.

Expected it should fetch the file from TestProject . i.e. the path should be /TestProject/src/main/resources/pmRolDetailsWithId.xml

I think the root project is not getting changed when the test control goes form TestRunner Project - TestProject

Please correct me If I am missing something and help me to resolve this issue.

Attaching screenshot of the error.

Screenshot of the error


Solution

  • I found the answer.

    I had to change the way I was giving the relative path of the file.

    Earlier - Filepath - /src/main/resoruces/pmRolDetailsWithId.xml

    and since execution was triggered from a different module, the complete path was
    /users/xyz/Parent-Module/TestRunner/src/main/resoruces/pmRolDetailsWithId.xml

    Changed - Filepath - ../TestProject/src/main/resoruces/pmRolDetailsWithId.xml

    And now the complete path was /users/xyz/Parent-Module/TestRunner/../TestProject/src/main/resoruces/pmRolDetailsWithId.xml