0 Replies Latest reply on May 16, 2008 11:44 AM by AndyMac

    Changing EntityManager at runtime for unit testing.

    AndyMac Newbie

      We're currently using Seam against remote Oracle databases. This is making our unit tests slow, and fragile, when people change the data in Oracle, the tests fail.


      I'd like to change our unit tests to use the Hypersonic In memory database, so that we can set up the db in a known state quickly before each test is run.


      There is a requirement that developers would like to run tests against both Oracle and HSQL in the same test run.


      We're injecting the EntityManager using the @PersistenceContext annotation.


      I've tried using the DataSourceDelegatorMBean (http://docs.jboss.org/jbossas/javadoc/3.2.7/varia/org/jboss/varia/dsdelegator/DataSourceDelegator.html).


      But it seems a bit hacky, I'd rather use a more 'Seam' way of doing things, if it's possible?


      Is the best solution to allow the users to override the EntityManager injected by supplying a setter, and getting the unit test datbase via an EntitymanagerFactory in the Unit Test?


      Thanks for any feedback,
          Andy