[jboss-user] [JBoss Seam] - SeamTest, Embedded EJB and TestNG issue

tarantula do-not-reply at jboss.com
Sat Feb 24 21:11:16 EST 2007


Hello,

I searched the forum before posting this but could not find a solution to this issue.

I'm not sure how other developers are testing their Seam/JSF applications but in my case I have dozens of test classes with hundreds of test methods that I would like to run as a single test suite.

The issue is that SeamTest initializes the embedded EJB container for each test class, and the embedded EJB container tries to create a connection pool-backed datasource but sometimes this fails and results in a variety of other side-effects and problems that cause my unit tests to fail.

For example, an EJB that needs the EntityManager won't get this dependency because the underlying datasource has not been created. Therefore this EJB is not fully initialized by @In(create=true) and cannot be injected into other EJBs, resulting in a cascade effect of null-pointer exceptions and other problems. 

A common problem is that the connection pool cannot acquire a database connection and times out, causing transactions to rollback. This is time consuming and really derails the testing process! :-)

Is there some reason why the EJB container needs to be initialized per class? Is this is a "lowest common denominator" approach because not everyone is going to be running TestNG suites, but everyone who uses SeamTest is going to be using TestNG classes?

If so, I can understand this but how can users that run test suites benefit from SeamTest?

I tried to override SeamTest.init() and SeamTest.cleanup() using TestNG's @Configuration(beforeSuite=true) and @Configuration(afterSuite=true) but this had other side-effects that I'm sure were not intended, eg. external context et. al. are not re-initialized for the second test class.

Ideally (in my case) SeamTest would init the EJB container once and only once when the test suite starts and shut it down when the test suite ends. I think this would dramatically increase unit testing performance and shorten the testing cycle considerably since the significant overhead of starting/stopping the EJB container is incurred only once per test suite.

SeamTest could provide a way for subclasses to choose a testing style. For instance, it could define two protected methods: isContainerNeededPerTestClass() and isContainerNeedPerTestSuite(). The default behavior could be container per test class but users like myself could use the container per test suite mode as needed.

Thanks for your time.

Ian

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4021827#4021827

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4021827



More information about the jboss-user mailing list