3 Replies Latest reply on Oct 12, 2005 5:51 AM by Pedro Kija

    how to JUNIT test ejb3

    J Chau Newbie

      I am trying to write junit tests for ejb3 session/entity beans and I downloaded the embedded EJB3 for this. However, in my junit tests i have start up the embedded Server in the setup() method. So for every test method in junit test case, it starts up the server. It takes about 6 seconds to start up. You can probably conclude that my unit tests are gonna be very slow when I accumulate more and more tests. This may not be acceptable.
      As an alternative, I wrote a test suite in which I start up the embedded Server in the beginning and I can persist it to the finish of all the tests in the test suite. This is not ideal because there is no actual teardown of my tests for every test method.
      Anybody have a better alternative?



        • 1. Re: how to JUNIT test ejb3
          Bill Burke Master

          mayb e I am ignorant, but I thought junit called setup at the beginning anyways?

          Also, as far as the 6 seconds goes, all I can say is that we're working on speeding it up.

          • 2. Re: how to JUNIT test ejb3
            Bill Burke Master

            Ok, after researching a little bit, here's a solution:

             public static Test suite() throws Exception
             {
             TestSuite suite = new TestSuite();
             suite.addTestSuite(EmbeddedEjb3TestCase.class);
            
            
             // setup test so that embedded JBoss is started/stopped once for all tests here.
             TestSetup wrapper = new TestSetup(suite)
             {
             protected void setUp()
             {
             startupEmbeddedJboss();
             }
            
             protected void tearDown()
             {
             shutdownEmbeddedJboss();
             }
             };
            
             return wrapper;
             }
            


            implement static methods startup and shutdownEmbeddedJboss and you are good to go.

            I will have a Junit testing example in the next release.


            • 3. Re: how to JUNIT test ejb3
              Pedro Kija Newbie

              Where can I find a tutorial of how to use JUnit with ejb3 (also with JBossIDE)?

              I'm new at ejb3, jboss-ide and junit and I'm completely lost.

              Thanks a lot.

              Regards.
              Pedro