TestNG does not work with JDK 6. TestNG works only with JDK 5. So, if you have JDK 6 installed on your system, you need to apply a little shrewdness.
I will assume that you already have JBoss Tools and the TestNG Eclipse plugin installed. If you need a tutorial on that, let me know and I’ll write one. I will also assume you are deploying in JBoss AS 5.
Here’s how to create a TestNG-ready Seam 2 project in Eclipse that works with JDK6:
- Create a new Seam 2 Project in Eclipse with the JBoss Tools wizard.
- If you project is gonna have EJBs, make sure you choose “EAR” as deployment at the end of the Wizard (but choose WAR at the Maven page).
- If you create a mavenized project, look for the warning “Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.”; rich-click on it, Quick Fix, Finish.
- Now you have the Seam 2 project and a Seam 2 test project
- In the test project, create a simple test class. For example:
- Right-click on the test class and select Run As –> TestNG Test
- If you have JDK 6, the test will fail with a daunting stack trace, and it’s ok. It fails because TestNG does not work with JDK 6, but only with JDK 5. But now, eclipse created a run configuration for us that we can fix.
- Now right-click again on the test class and select Run As –> Run Configurations
- In “Run configurations” window, scroll down and find TesNG –> NameOfYourTestClass
- Select the “(x)=Arguments” tab
- In the “VM Arguments” field past the following:
-Dsun.lang.ClassLoader.allowArraySyntax=true
- Click “Apply” then “Close”
- Right-click again on your test class and select Run As –> TestNG Test. Now the test will run.
- Repeat steps 6 to 12 for every test class you create. Make sure you remember to do so!
- Happy testing!
package test; import org.jboss.seam.mock.SeamTest; import org.testng.annotations.Test; public class Tests extends SeamTest { @Test public void myFirstTest() { assert true; } }