-
1. Re: TestNG fails in by Seam Web Project generated eclipse Project
juergen May 5, 2009 9:16 AM (in response to roniraja)I'm facing the same problem.
Please can anybody give a hint?!
Thank you!
-
2. Re: TestNG fails in by Seam Web Project generated eclipse Project
mikkus70 May 16, 2009 1:33 AM (in response to roniraja)This error is caused by the fact that your persistence.xml is configured to use a JTA transaction manager and you're instantiating the EntityManager directly.
SeamTest is perhaps
too
smart... it configures your application to be tested inside a container (JBoss Embedded), so if you create the EntityManager by hand you'll be conflicting with your persistence unit configuration (probably your persistence.xml uses JBossTransactionManagerLookup or has transaction-type="JTA"), which expects you to use the container's transaction manager.So, instead of hand creating the EntityManager, just inject it as you would inside the container (because you're actually using it inside a container). If your unit tests are not being run from within the container (i.e., you're not using SeamTest but directly derive your test classes from TestCase), then you need to create a separate persistence.xml for testing purposes, in which you use transaction-type="RESOURCE_LOCAL" and refrain from using several features of hibernate that only work with JTA transaction managers (such as second level cache). But if you're creating EJBs, they are best tested within an EJB container.
Ideally, you would want to use SeamTest's added features, such as testing from within a
full
-featured container, which tests your EJBs in the same ecosystem they'll find in production... You can bypass SeamTest in other contexts, for example if you're testing POJOs that don't use the database, seam injection, jndi lookups or other container-specific features.For database-specific testing, SeamTest also provides support for DBUnit, which lets you easily populate your database with sample data. I use this setup very effectively with an HSQLDB memory database.