0

Here's my problem.

I'm using a single project with so many testClass

--Package
----TestClass1
----TestClass2
----TestClass3

Every testClass is a test suite, that contains it's own beforeTest, test and afterTest annotations

I want to implements a number of jenkins jonbs as much as testClass

Now my only dummy solutions is to duplicate project and create a single testClass for each job.

Is there a way to say to maven to point at a class by it's name, or something similar to that ? Someting like mvn clean test -D=className

Sorry for my english

Hamza Amami
  • 43
  • 1
  • 5

3 Answers3

2

You can set the command line property surefire.includesFile to a file, in which you list the relevant classes. See also

https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

where you should be looking for "includesFile".

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Thanks How I can configure my jenkins to execute the right class with surefire ? is there something to add in the execution command ? – Hamza Amami Mar 01 '19 at 15:49
1

You can just pass in the test name as part of the maven params i.e.

-Dtest=TestClass1, TestClass3 test

to run TestClass1 and TestClass3

More examples found @ How to run multiple test classes or test methods using Maven?

mkane
  • 880
  • 9
  • 16
1

Create a TestClass1.xml file for specific Test class.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
      <class name="com.tutorial.testng.TestClass1"/>
    </classes>
  </test>
</suite>

Now use dynamic xml file name in 'maven-surefire-plugin' as mention below.

<configuration>

        <suiteXmlFiles>

            <!-- TestNG suite XML files -->
         <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>

        </suiteXmlFiles>


</configuration>

Now you can utillize run it via maven

mvn clean test -Dsurefire.suiteXmlFiles=TestClass1.xml

In Jenkins, you can create job with "build with parameters" and create a string parameter. Now you can pass testng.xml in Jenkins. Check below how to do it.

https://www.theserverside.com/video/Modify-CI-jobs-with-this-Jenkins-parameterized-build-example

Hope it will help.

Muzzamil
  • 2,823
  • 2
  • 11
  • 23