Showing posts with label TestNG. Show all posts
Showing posts with label TestNG. Show all posts

Tuesday, January 6, 2009

Seam-Gen and the TestNG plugin

Here's an interesting heads up to running SeamTest classes inside Eclipse.

I was having some problems getting my tests, extending SeamTest, to run with the Eclipse TestNG plugin. I found this post on seamframework.org which states,

"the Eclipse Run dialog to start the TestNG test will only be viable if you have a Seam Web Project created from JBoss Tools"

I used Seam-Gen instead of JBoss Tools for my project. I ran the tests from ant and they worked.

Friday, January 2, 2009

SeamTest and Eclipse TestNG plugin

I encountered a small problem running a new SeamTest with Eclipse' TestNG plugin. The error was :

DEBUG [main] (KernelFactory.java:86) - Starting JBoss Kernel construction...
DEBUG [main] (KernelFactory.java:112) - Completed JBoss Kernel construction. Duration: 381 milliseconds
FAILED CONFIGURATION: @BeforeSuite startSeam
org.jboss.deployers.spi.DeploymentException: Unable to find bootstrap file: conf/bootstrap-beans.xml in classpath
at org.jboss.embedded.Bootstrap.bootstrap(Bootstrap.java:181)
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:1025)
at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:916)
at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
... Removed 15 stack frames
The solution is pretty simple.

Open up the run configuration (the arrow next to the run button and choose "Run Configurations...")
The most recently run test should be highlighted. If not select it.
Choose the "Classpath" tab in the right side of the pane.
Click "User Entries" which should be in the center pane.
Click "Advanced' -> "Add Folders" -> OK and navigate to the "bootstrap" folder.
Click "Add Jars" and navigate to the "lib/test" folder and add all three jars.




Ok.

Wednesday, October 10, 2007

Seam-gen and TestNG problems

I created a project using Seam-gen, taking the database defaults (I wanted hsqldb for development anyway.)

First thing I wrote a test for the Manager/Action class that I was starting with. I also added a testng.xml to the src/test folder. I was using Eclipse so I right clicked on the build.xml's test target and ran it. Nothing.

The testng.xml file wasn't get copied to the test-build directory so I updated the build.xml withe the following :
  • test target - changed line 315 to read <xmlfileset dir="${test.dir}" includes="testng.xml" /> instead of <xmlfileset dir="${test.dir}" includes="*Test.xml" />
  • copytestclasses target - added <include name="*.xml" /> in the last copy statement so that the testng.xml file was copied from classes/test directory along with the class files
  • copytestclasses target - removed "if='eclipse.running'" from the target. I don't know why, but the files weren't copied at all with this qualifier even though I was running out of Eclipse.
The test ran from build.xml.

Right clicking and running the TestNG plugin didn't do anything though. I opened the Run dialog (Run -> Open Run Dialog) and updated the classpath of the TestNG test to include the lib/test folder and ran the test from there. I got a different but no better result. (The stack trace is pasted below in the possibly vain belief that someone may stumble onto this posting while Googling the same problem)

javax.persistence.PersistenceException: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

I found this entry on JBoss' Forums which suggested using a non-jta-data-source in the persistence-test.xml. I updated my persistence-test.xml to the following (changes in bold) :

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for tests -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">

<persistence-unit name="project_name" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/project_nameEntityManagerFactory"/>
</properties>
</persistence-unit>

</persistence>

That did the trick; although, it doesn't appear that my test data is getting loaded. I'll blog that solution later.

Blogged with Flock

Tuesday, October 9, 2007

Seam and TestNG and a missing rar file

Generated a new project with seam-gen.

Had a problem with the build.xml's "test" task. I got the error "You need to specify at least one testng.xml or one class"

I downloaded last night's snapshot from JBoss. (On a side note, I've started using Hudson after seeing it used by JBoss, and its very nice. I like it more than Continuum and CruiseControl.) Same error.

I added a testng.xml file to src/test directory.

I changed buildxml :
added "<include name="**/*.class"/>" to line 282
added "<copy tofile="${test.dir}/testng.xml" file="${src.test.dir}/testng.xml" overwrite="true"/>" to line 296.
changed line 320 (324 after adding the above) to "<xmlfileset dir="${test.dir}" includes="testng.xml" />"

The test ran, which was good; however, there were errors in the output.
"Error parsing meta data jboss-local-jdbc.rar"

Looking through the output I noticed that there was an io.FileNotFound for "C:\Documents%20%and%20%Settings." The actual file was referenced correctly in several of the other lines, but I decided to start over with seam-gen and put the folder directly on the C drive with no spaces.

It worked.

The moral : put my Eclipse workspaces on the C drive.

Blogged with Flock