How to execute a java main class along with a testng.xml using Maven

1,912 views
Skip to first unread message

Mahesh

unread,
Feb 25, 2016, 9:55:46 AM2/25/16
to testng-users
Guys, anyone having idea on how to execute a simple java (main) class before a testng suite file starts executing during Maven Test phase

Krishnan mahadevan

unread,
Feb 25, 2016, 10:55:10 AM2/25/16
to testng...@googlegroups.com
Why do you want to do this ? Can you please add more context to your query ?

-Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else"

From: Mahesh
Sent: ‎25-‎02-‎2016 20:25
To: testng-users
Subject: [testng-users] How to execute a java main class along with atestng.xml using Maven

Guys, anyone having idea on how to execute a simple java (main) class before a testng suite file starts executing during Maven Test phase

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Raju Arelli

unread,
Feb 26, 2016, 6:57:11 AM2/26/16
to testng...@googlegroups.com
Hi Mahesh,

Please refer the below,I think it may help you.

public class XmlMainClass {

      

 @Test

public static void main(String[] args) {

 

// Create object of TestNG Class

TestNG runner=new TestNG();

 

// Create a list of String

List<String> suitefiles=new ArrayList<String>();

 

// Add xml file which you have to execute

suitefiles.add("Path of your XML File");

 

// now set xml file for execution

runner.setTestSuites(suitefiles);

 

 

 

// finally execute the runner using run method

runner.run();

}

 

}

 


Regards,

Raju


On Wed, Feb 24, 2016 at 7:36 PM, Mahesh <mahes...@gmail.com> wrote:
Guys, anyone having idea on how to execute a simple java (main) class before a testng suite file starts executing during Maven Test phase

--

Krishnan Mahadevan

unread,
Feb 26, 2016, 8:25:06 AM2/26/16
to testng...@googlegroups.com
Raju,
main() methods dont get executed by surefire-plugin when you invoke the test phase via mvn clean test.

So I don't think this would work. What you have shared here is a sample to show how to use the TestNG APIs and run tests manually via a main method.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Yevhen B

unread,
Feb 29, 2016, 1:26:04 AM2/29/16
to testng...@googlegroups.com

Mahesh,

Don't have a working example,  but you may setup maven exec plugin to execute your main in pre-test phase

YB

Reply all
Reply to author
Forward
0 new messages