0

I would like to execute a java class which consists a main method (this creates a testng.xml file) before my test phase starts (which consists of class with @Test methods).

Is it possible to execute this class before test phase using any command of maven? I want to run my tests using jenkins so I need to provide a goal which can perform this task.

Currently I use command "mvn test" to execute my tests.

Thanks, Sunil

lance-java
  • 25,497
  • 4
  • 59
  • 101
Sunil Ojha
  • 223
  • 1
  • 7
  • 20
  • 3
    There is a Goal `generate-test-sources` where you can add the function. it will be executed before the test phase – Jens Sep 08 '16 at 13:14
  • look at the linked answer, you can configure the `exec-maven-plugin` to run your Java main during a [phase](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html) before the `test` one, as @Jens suggested – A_Di-Matteo Sep 08 '16 at 13:25
  • I've added the below in my pom.xml but I'm still not able to execute it: ` org.codehaus.mojo exec-maven-plugin 1.5.0 Maven executions test test com.test.CreateTestNGXML ` which command should I execute to execute class 1st? – Sunil Ojha Sep 08 '16 at 13:55
  • @SunilOjha you shouldn't execute in `test` phase but a phase **before** it, `generate-test-sources` would be fine as suggested above, also reading the linked documentation about phases would help :) – A_Di-Matteo Sep 08 '16 at 14:12
  • It worked. Thanks @A_Di-Matteo and Jens for helping. – Sunil Ojha Sep 08 '16 at 14:16

0 Answers0