Unit Testing with TestNG and Seam
When using the test cases build for TestNG within JBoss Seam you do not need to run an Application Server explicitly. The Testing Framework delivered with Seam uses an JBoss Embedded (http://www.jboss.org/community/wiki/EmbeddedJBoss) to execute the tests.
If you have created a Seam project by using seam setup (and in case you use Eclipse calling seam new-project) and just want to execute the tests within Eclipse using the TestNG-Plugin, take care of using the XML file (where the test cases and test suits are declared) and say Run as TestNG Suite. If you use the Java file containing the test and execute it as Run as TestNG Test you get the following error:
ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Described: name=BeanDeployer state=PreInstall
java.lang.RuntimeException: java.lang.reflect.UndeclaredThrowableException
at org.jboss.aop.util.ClassInfoMethodHashing.methodHash(ClassInfoMethodHashing.java:70)
at org.jboss.aop.util.ClassInfoMethodHashing.addDeclaredMethods(ClassInfoMethodHashing.java:169)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:182)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181)
at org.jboss.aop.util.ClassInfoMethodHashing.populateMethodTables(ClassInfoMethodHashing.java:181)
...
FAILED CONFIGURATION: @BeforeSuite startSeam
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
UserTransactionBinding
-> UserTransaction{Configured:**ERROR**}
UserTransactionBinding2
-> UserTransaction{Configured:**ERROR**}
*** CONTEXTS IN ERROR: Name -> Error
SARDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
ServiceDeploymentDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
ServiceClassLoaderDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
BeanDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
ServiceDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
BeanMetaDataDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
UserTransaction -> java.lang.RuntimeException: Unable to locate the transaction manager
KernelDeploymentDeployer -> java.lang.ClassNotFoundException: [Ljava.lang.Class;
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:576)
at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:559)
at org.jboss.embedded.Bootstrap.bootstrapURL(Bootstrap.java:149)
at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:183)
at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:195)
at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:11)
at org.jboss.seam.mock.AbstractSeamTest.startJbossEmbeddedIfNecessary(AbstractSeamTest.java:1024)
at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:915)
at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
... Removed 15 stack frames
SKIPPED CONFIGURATION: @BeforeClass setupClass
SKIPPED CONFIGURATION: @BeforeMethod begin
SKIPPED CONFIGURATION: @AfterMethod end
SKIPPED CONFIGURATION: @AfterClass cleanupClass
SKIPPED: test_myFirstAction
===============================================
com.mydomain.mySeamTestProject.test.MyFirstActionTest
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 4
===============================================
===============================================
mySeamTestProject
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 5
===============================================
``````
*BUT:* If you get the error message from above while trying to start Tomcat with embedded JBOSS you maybe forgot to set this JVM parameter:
-Dsun.lang.ClassLoader.allowArraySyntax=true
You can put that in the startup script:
set CATALINA_OPTS=-Dsun.lang.ClassLoader.allowArraySyntax=true ``` See http://community.jboss.org/thread/152277.