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:

  1. Create a new Seam 2 Project in Eclipse with the JBoss Tools wizard.
  2. 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).
  3. 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.
  4. Now you have the Seam 2 project and a Seam 2 test project
  5. In the test project, create a simple test class. For example:
  6. package test;
    
    import org.jboss.seam.mock.SeamTest;
    import org.testng.annotations.Test;
    
    public class Tests extends SeamTest {
    
    	@Test
    	public void myFirstTest() {
    		assert true;
    	}
    }
    
  7. Right-click on the test class and select Run As –> TestNG Test
  8. 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.
  9. Now right-click again on the test class and select Run As –> Run Configurations
  10. In “Run configurations” window, scroll down and find TesNG –> NameOfYourTestClass
  11. Select the “(x)=Arguments” tab
  12. In the “VM Arguments” field past the following: -Dsun.lang.ClassLoader.allowArraySyntax=true
  13. Click “Apply” then “Close”
  14. Right-click again on your test class and select Run As –> TestNG Test. Now the test will run.
  15. Repeat steps 6 to 12 for every test class you create. Make sure you remember to do so!
  16. Happy testing!
 

Leave a Reply