How do you unittest your entity beans? Is there any way to do it without the server running? Also, how do you test the session beans that call the entity beans (without the server running) ? The only thing I came up with is to use an interface to get the entity beans and return the real entity bean or a mock bean. But this seems more involved than other tests I've written with junit.
You could check out MockEJB for unit testing Session and Message Driven Beans outside of an EJB Container. It currently does not support Entity Beans, though some form of support seems planned for the future. Disclaimer: I have not used this library so I cannot attest to its quality. I try to keep my business logic cleanly separated from and ejb layer and limit the ejbs to thin facades on top. This then makes unit testing the business logic outside of the EJB Container easy. For persistance, I usually stay away from Entity Beans (even CMP) and choose instead to wrap the persistance layer with Session Beans. In simpler applications I usually choose plain DAO for persistance or a good O/R mapper like Hibernate for more complex applications. This allows the persistance layer to also be easily unit tested outside of the EJB Container. In general, I try to stay away from unit testing that requires a running EJB Container when I can.
I do use junit for other things. Upon further thought, I could use junit to test the method I'm thinking about adding to the entity bean. The only other custom thing is finders, which I would expect to need a server to test. Chris, MockEJB looks interesting (although it doesn't do what I'm looking for. I'll have to try it out sometime.) I do have the business logic separated into a separate class that is called from the session bean. I'm not clear on how that makes it easier to test though. I still have that new class that is trying to execute entity beans (or DAOs in your example.) I agree that it is good to stay away from needing the server for writing tests. I've used MockObjects and it looks like I'll need to do that here as well.