0

I want to package a TestNG project to a Jar. I have got n number of testng xml files and only few xml are needed to be executed during the execution. The selection of the xml file to be run is done through maven pom.xml for example:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <!-- Suite testng xml file to consider for test execution -->
        <suiteXmlFiles>
            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

Here the actual xml name or path is not given but it is passed as an argument through maven command line. I wanted to know if I can achieve the same if I package the project to jar and if I can pass the xml file name to the jar execution command and I can execute that particular xml file. Is it possible? Hope anyone can help.

what i'm trying to achieve is something like this

java -jar -Dxml=integration.xml name.jar 
azhar
  • 11
  • 1
  • 4
  • Why do you want to execute test at runtime? Maven is only doing its job (incl. executing the tests) at build time – Robert Kleinschmager Jun 16 '20 at 04:37
  • Because I want to take the packaged jar to the production and pre-prod and there in the Jenkins I want to run the specific tests only not all the tests. Requirements may change. Sometimes all the tests needs to be executed and sometimes only few. Please suggest if there're any other ways I can achieve this. – azhar Jun 16 '20 at 05:16
  • So you don‘t have the source available at Production Jenkins or Pre-Prod Jenkins? – Robert Kleinschmager Jun 16 '20 at 05:24
  • I was checking if there's any solution to get over with without the sourcecode being copied there. – azhar Jun 16 '20 at 06:54
  • Maybe this will answer your question: https://stackoverflow.com/questions/36047637/how-can-i-include-test-classes-into-maven-jar-and-execute-them – Robert Kleinschmager Jun 16 '20 at 10:58
  • Thanks Robert Kleinschmager that helps and it gives an idea how to proceed – azhar Jun 17 '20 at 10:44

0 Answers0