You can always instantiate the beans directly and test them as you would in an ordinary JUnit test.
If this is not sufficient, perhaps you could post some code showing what you would like to do?
Thans for your answer Stan.
The problem I have:
I use Maven2 to build my projects.
The "user interface" project gets built as WAR.
As I am using Cactus to test our application I created a parallel Maven project just for testing.
-main pom |
| - UI
| - EJB1......
- Tests (using above EAR file to cactify + code)
The EJBs I can access per lookup:
InitialContext ic = new InitialContext();
CustomerocalHome application_home = (CustomerLocalHome)ic.lookup("java:/local/Customer");
customerEJB = customer_home.create();
Which works great.
The problem with testing the UI is following:
As the get built OUTSIDE the WAR file I'm not able to access the MBeans (even when I put a dependency into the Test project).
Which leaves me two possibilities:
1. Call the backing beans "remotely" like the EJBs (I haven't found any solution for this)
2. Move the test files INTO the UI WAR, but I don't want the tests deployed when i build a release candidate (only for testing porposes)
Currently I build the Test project for testing purposes.
By building the application "itself" i create an EAR file without tests (that EAR file i deploy on our staging+live servers).
For any help I would be grateful,
I see three options:
- Put ordinary JUnit tests in your UI project. Since these are ordinary (non-cactus) tests, they won't be deployed with the WAR.
- Put your managed beans in a seperate module with its own jar and test them in the new module.
- Put your managed beans in a seperate module with its own jar and test them along with your JSFUnit tests.
I'd probably choose #1, but I'd put more energy into your JSFUnit tests than the ordinary tests. Ordinary tests are great when you first go to develop one or two complex beans that work together. But artifacts like managed beans that are meant to run in a JSF environment need to be tested thoroughly in that environment for the tests to be meaningful.