Maven - TestNg Query

10 views
Skip to first unread message

Bharath kumar

unread,
Sep 5, 2018, 10:47:32 AM9/5/18
to qapl...@googlegroups.com
Hi Experts,

I'm working on Maven-TestNG framework, I'm able to execute my test suite via eclipse IDE, and command prompt successfully.

I'm facing problem when i tried to execute via jar file as i'm getting "no main manifest attribute" error. 

It is complaining about main method, but since this is a testng framework, I'm not using main() method anywhere. 

How can we go about this ?

jeedimetla dinesh

unread,
Sep 5, 2018, 11:19:19 AM9/5/18
to qapl...@googlegroups.com
Hi Bharath,

To execute jar, it need to specify some entry point .i.e., mainfest class.

You need to create new java class which has main method calling testng run.
Then mention above path of java class as mainfest attribute in maven pom.xml file

Below is sample code of java class that need to be added:

import java.io.File;
import java.util.List;

import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.collections.Lists;

public class ExecuteTestSuite {

public static void main(String[] args) {

TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
                suites.add(new File("Path to testng suitefile").getAbsolutePath().toString());
                testng.setTestSuites(suites);
testng.addListener(tla);
testng.run();
System.out.println("Test Completed!!");
}
}

Tip: There are lot thing that we can do with testng listeners, just google it!

Add below line in maven pom file:

<manifest>
<mainClass>package path to ExecuteTestSuite class</mainClass>
</manifest>


Hope this helps.

Thanks
Dinesh

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


--
dinnu
Reply all
Reply to author
Forward
0 new messages