testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k stars 1.02k forks source link

Cascading suite xml's are not run from jar with -xmlpathinjar, only initial xml #2942

Closed ZathrasOne closed 1 year ago

ZathrasOne commented 1 year ago

TestNG Version

Note: only the latest version is supported 7.6.1, 7.3.0

Expected behavior

When running XML from a jar, and that XML includes a suite-file, TestNG should look in the jar for that file as well

Actual behavior

TestNG looks on disk instead of in the jar C:\Users\brucer\SuiteTEST>java -cp ./* org.testng.TestNG -testjar TestngEmbeddedSuitesTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar -xmlpathinjar src/TestNG/masterSuite.xml [TestNG] [ERROR] java.io.FileNotFoundException: C:\Users\brucer\SuiteTEST\src\TestNG\suite1.xml (The system cannot find the path specified)

Is the issue reproducible on runner?

Test case sample

Please, share the test case (as small as possible) which shows the issue

src/TestNG/Suite1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Service Operations tests" parallel="none">
    <parameter name="TakeScreenShotOnFailure" value="true" />
  <parameter name="EnvProfile" value="UAT_OPERATIONS"/>
    <test name="Test Patients tests">
        <classes>
            <class name="org.testng.test.class1" >
                <methods>
                    <include name="method1" />
                </methods>
            </class>
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

src/TestNG/Suite2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Service Operations tests" parallel="none">
    <parameter name="TakeScreenShotOnFailure" value="true" />
  <parameter name="EnvProfile" value="UAT_OPERATIONS"/>
    <test name="Test Patients tests">
        <classes>
            <class name="org.testng.test.class2" >
                <methods>
                    <include name="method1" />
                </methods>
            </class>
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

src/TestNG/masterSuite.xml:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Main suite"> <!--commenting parallel="suite-file" thread-count="2" -->
    <test name="Test Patients tests">
        <classes>
            <class name="org.testng.test.class1" >
                <methods>
                    <include name="method1" />
                </methods>
            </class>
        </classes>
    </test> <!-- Test -->
    <suite-files>
        <suite-file path="src/TestNG/suite1.xml" />
        <suite-file path="src/TestNG/suite2.xml" />
    </suite-files>
</suite>

org/testng/test/class1.java

package org.testng.test;
import org.testng.annotations.Test;
public class class1 {

    public class1() {
    }
    @Test
    public void method1()
    {
        System.out.println("Executing class 1 method1");
    }
}

org/testng/test/class2.java

package org.testng.test;
import org.testng.annotations.Test;
public class class1 {

    public class1() {
    }
    @Test
    public void method1()
    {
        System.out.println("Executing class 2 method1");
    }
}

Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

krmahadevan commented 1 year ago

I have tried reproducing this issue using TestNG 7.8.0 (this requires JDK11) using the below attached project and I am not able to recreate this issue.

java -cp target/issue_2942.jar org.testng.TestNG -testjar target/issue_2942.jar -xmlpathinjar master_suite.xml

Sample Project used: issue_2942.zip

If this is still a problem please feel free to share a sample project that can be used to reproduce the problem.