Bug 234138 - Tools for easy EJB testing
Summary: Tools for easy EJB testing
Status: NEW
Alias: None
Product: WTP EJB Tools
Classification: WebTools
Component: jst.ejb (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Kaloyan Raev CLA
QA Contact: Kaloyan Raev CLA
URL: http://wiki.eclipse.org/WTP_UX_Whiteb...
Whiteboard: UX EaseOfUse
Keywords: usability
Depends on: 265952
Blocks:
  Show dependency tree
 
Reported: 2008-05-27 08:44 EDT by Kaloyan Raev CLA
Modified: 2009-08-13 12:44 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kaloyan Raev CLA 2008-05-27 08:44:19 EDT
Pain point

EJB developers have no easy way to test their EJB artifacts. They need to install an EJB-enabled appication server that typically consumes significant resources on their developer's machines. JUnit tests have to be written manually from scratch. 

Solution

EJB developers would appreciate tools that enables them to easily test developed EJB artifacts. Such tools could be:

    * a framework for generating JUnit test stubs out from EJB beans.
    * a lightweight EJB container that runs locally and enables developers to test their EJB beans without a need of full-blown Java EE application server.
    * an integration between the JUnit generation framework and the lightweight EJB container where the tests would be executed.
Comment 1 Kaloyan Raev CLA 2008-07-22 06:34:32 EDT
I have just found OpenEJB - an Apache project that provides a lightweight EJB 3.0 container. 

Project site: http://openejb.apache.org

There is also an Eclipse plug-in provided:
http://openejb.apache.org/openejb-eclipse-plugin.html
Comment 2 Kaloyan Raev CLA 2008-08-01 11:26:58 EDT
I have just posted a blog about installing OpenEJB server adapter in Eclipse:
http://dev.eclipse.org/blogs/raev/2008/08/01/lightweight-ejb-container-in-eclipse/

We may start thinking about embedding OpenEJB in the J2EE Preview runtime. 
Comment 3 kiril mitov CLA 2008-08-14 04:11:00 EDT
There are from my point of view several ways to test EJBs.

In-container.
The ejb is running in an ejb container. All injections are valid. The test is run in the same container in the form of another ejb.

Out-side the container.
The ejb is running in an ejb container. Test is run outside the container. Probably in a separate virtual machine. The test is getting a reference to the ejb and is remotely executing some tests for the ejb. 
This JUnit test might be written 
-in a form of a servlet that is injecting the ejb. The servlet is running on the server side. 
-in a form of a client project that is looking up for the ejb using the InitialContext and is executing tests for the ejb. Again client projects are executed on server side.
-in a form of standalone junit test that is running on the client side. Connecting with the server, looking up a reference to the bean, calling methods of the bean.

Since looking up a bean from the server with the InitialContext is server depended, what WTP, and server adapters could provider is a way to generate this lookup.

Mocking is also a good technique for testing ejbs. No need to have the container. 
The basic principle for writing good tests is "to test only your code". This mean the code of the ejb. One should not need to test the container, so she should not need to run ejb in a container. 

I think it is best to unit test the ejb as a simple java class outside of the container using simple JUnit tests. With simple design decisions the ejb can be easily mocked. For example: injection.
As the ejb spec states one can inject a bean using 
-field
@ELB private LocalInterface bean;
-method
@EJB public void setBean(LocalInterface bean).

Using the first approach the bean can not be mocked. But with the second approach injection can be very easily mocked. No need from a container.

I thing that embedding a lightweight EJB container is not a bad idea, but testing ejbs is not enough for taking such a decision.
Comment 4 Kaloyan Raev CLA 2009-02-24 08:51:14 EST
I have opened bug 265952 for embedding OpenEJB in the J2EE Preview adapter.