Testing using JUnit 4 and EJB3


EJB programming & troubleshooting: Testing using JUnit 4 and EJB3

  1. Testing using JUnit 4 and EJB3 (2 messages)

    I've been attempting, without any luck, to get server-side JUnit tests to test my EJB3 code in-container using the new, annotation-style JUnit 4 tests. I'm using the Ant 1.7 to deploy my code and run my tests, as this version has JUnit 4 functionality built in. I attempted to use both JUnitEE and Cactus to run my tests. I was successfully able to get JUnitEE to run JUnit 3.8 style tests, but the various permutations of configurations I tried using JUnit 4 failed to work. I tried with and without the JUnit4TestAdapter in a suite() method. I was getting different depending on the setup I was using. If I have the opportunity later, I'll post the errors I was getting and the setups. However, I did try various things to no avail. My attempts to get cactus working seemed to meet with more success, and the tests do run. However, I am skeptical as to whether my setup is actually running the tests from the sever, and not on the local box. The reason I say that is that when I forgot to package some jars that were necessary to the build, the ant tests still ran and passed. However, when I used the cactus servlet to run the tests manually, they would fail. Here's the relevant section of my ant script for my cactus tests. Note, it's pretty messy at the moment, as the goal was more to get things working than to have a clean final script. <!-- Create the war file --> <!-- todo: build actual war for actual app; then have cactified copy --> <!-- Run the tests --> <!-- todo: do integration tests instead, once this is working --> Cactus JUnit test failures Beginning (re)deployment of servlet at ${webserver.tests.url} Waiting for servlet to be undeployed... Unable to undeploy previous servlet Waiting for servlet to be deployed... Unable to deploy servlet Any help I could get concerning this would be most appreciated. Google, and searching various java forums hasn't turned up anything useful. For that matter, just letting me know if you've had similar difficulties, or no difficulties with the same task would be useful, as it'd give a hint as to whether I'm missing something obvious. Thanks.
  2. The open source project EJB3Unit automates Entity and Session bean testing outside the container for the EJB 3.0 specification. Ejb3Unit can execute automated standalone JUnit test for all EJB 3.0 conform J2EE projects. This could might be an alternative for in container testing with catus. See http://ejb3unit.sourceforge.net/
  3. Ejb3 Unit 2.0 is comming[ Go to top ]

    After 7000 downloads and more than 6 month development, Ejb3Unit 2.0 is is coming (http://ejb3unit.sourceforge.net/Roadmap.html)!!! This are the new features: * No dependencies - on jar thats it!! (only log4j.jar and optional jmock.jar [for mocked tests] will be required). This will ease the installation and development in large projects because less dependencies are required. No jar file conflicts anymore! * Support for relational CSV data loaders. Load your test data with references! * Support for peristence.xml no need to specify your persistence objects for every test! * Completely refactored EntityManger life cycle handling - will speed up your testing! * Support of the new jMock2 framework! * More feedback for failing test cases! * Broken entities (e.g. syntax error in query) will not break other tests anymore! * Lots of bug fixes!