5 Replies Latest reply on May 4, 2007 7:55 AM by Alexander Torstling

    EjB3 & JBoos AS - JUnit testing

    Karl Martens Newbie

      Hi,
      I am try to crate an ear using the following technologies:

      * JBoss AS 4.0.5.GA with EJB3
      * JBoss Embeddable EJB3 Container
      * Hibernate 3
      * JUnit

      I have been able to create an ear the deploys and executes on the JBoss AS but when the same code is executed with JUnit in the embeddable EJB 3 container the dependent EJBs do not get injected as I expected.

      Tracked the problem down to the different annotations being used in the JBoss AS (javax.ebj.ejb) vs Embeddable container (javax.annotation.ejb).

      Changing the annotation to other one got the code working on the embeddable container but now fails on the JBoss AS (as one would expect).

      Does anyone know a way that I can have the same code run deployed on a JBoss AS and testable with JUnit?

      Some options I'm exploring but not having any luck on finding people that have managed to accomplish:
      1) Upgrade embedded ejb3 container to use same annotation as JBoss AS
      2) Run JBoss AS server in same JVM as JUnit runner

      Would greatly appreciate any advice anyone can offer, even if its different then the approaches I've described above.

      Thanks

        • 1. Re: EjB3 & JBoos AS - JUnit testing
          Baskaran Balasubramanian Newbie

          Hi karl...

          sorry for this reply this mite not be appropriate to ask u but.. could u help me develope an EJB3.0 application in eclipse 3.2 or jboss ide 1.6..

          which one would better.. kindly help me out.

          • 2. Re: EjB3 & JBoos AS - JUnit testing
            Alexander Torstling Newbie

            You can use Jakarta Cactus. This is essentially a two-component solution that has a local test runner that interfaces to a test runner servlet on the server via IP. I guess you already considered the other alternative: to connect as a client and setup preconditions via a direct connection to the db or similar.

            • 3. Re: EjB3 & JBoos AS - JUnit testing
              Karl Martens Newbie

              I've just had a brief look at the Jakarta Cactus and it look promising. I will investigate and see if I can get it to work for my needs.

              AS far as connecting as a client it depends what you mean. I had considered using a test running like Watir and Ruby to test the application via http request response. I will use this approach for high level business case tests but I've found that the speed of these type of tests make it difficult to get high degrees of test coverage.

              If you meant connecting directly to the EJBs vie a remote interface, I hadn't considered that.

              Thanks for your reply much appreciated, gave me something to consider.

              • 4. Re: EjB3 & JBoos AS - JUnit testing
                Karl Martens Newbie

                Karan42in - I've moved your question with reply to its own thread http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043113#4043113

                If you or anyone else has something to say on your topic I would ask that all responses be directed to the new thread.

                Thanks.

                • 5. Re: EjB3 & JBoos AS - JUnit testing
                  Alexander Torstling Newbie

                   

                  "karl.martens" wrote:
                  I've just had a brief look at the Jakarta Cactus and it look promising. I will investigate and see if I can get it to work for my needs.

                  AS far as connecting as a client it depends what you mean. I had considered using a test running like Watir and Ruby to test the application via http request response. I will use this approach for high level business case tests but I've found that the speed of these type of tests make it difficult to get high degrees of test coverage.

                  If you meant connecting directly to the EJBs vie a remote interface, I hadn't considered that.

                  Thanks for your reply much appreciated, gave me something to consider.


                  No problem. Unit testing of EJB:s is still a pain I think. I've really been waiting for the embeddable container, since this would simplify a great deal. I usually write separate ejbs for unit testing, just to be able to inject any dependencies I need. Regarding the client high level-approach, I agree with you that it's pretty useless since the pre and postconditions are to much of a hassle to check. Would be sweet to have a TestNG-pojo and just get the entity manager in a nice and clean way. Of course, this requires being in the same JVM, and hence you need to deploy the tests to the server (cactus helps here), or start the server in local JVM (embeddable).

                  The other problem I'm having is that maven expects the tests to be able to run directly after compilation, which usually makes me having a separate subproject for my ejb unit test. This does encourage refactoring a lot of logic into utility classes (makes that logic easily testable) , which I think is good, but the tests needs to be separated from the actual build and deploy process, which I think is really bad.

                  I like this discussion. Does anyone have a nice clean solution for how to unit test J2EE projects?

                  I'm happy to contribute with the stuff I've came up with (config, patterns, code etc).

                  Regards