Solved

Stateless session bean

Posted on 2010-09-15
7
481 Views
Last Modified: 2012-05-10
Stateless session bean using JPA for persistence  are most thoroughly testable outside a container without requiring the creation of mock objects

I don't understand this .

It seems to me , this is impossible.  Stateless session bean  can not live outside container ...how come then we test  ? Also Test without creating any objects of the bean !

This is impossible ...is not it ?  Can we really do it ?
0
Comment
Question by:cofactor
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Hegemon
ID: 33681140
It is just an annotated POJO so you don't need container to test.
0
 

Author Comment

by:cofactor
ID: 33681161
>>>It is just an annotated POJO
which one ?
Stateful session bean live in EJB container.
>>>so you don't need container to test.
How you are going to test that ?
jakarta Logger will not work unless you deploy .
System.out.println  will not work unless you deploy .
Not sure about Junit / EJB3 Interceptor though
 
0
 
LVL 10

Accepted Solution

by:
Hegemon earned 300 total points
ID: 33681415
-- which one ?

All EJB 3.0 are POJOs

>>>so you don't need container to test.

-- How you are going to test that ?

Write unit test as you would normally do for POJOs

-- jakarta Logger will not work unless you deploy .

It is not a unit test then since you are not testing your classes in isolation. You should be mocking the logger.

System.out.println  will not work unless you deploy .

-- Incorrect, it will work in any environment.

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:cofactor
ID: 33684494
yea...its better now.

Could you please explain this part in your comment

>>>Write unit test as you would normally do for POJOs

did you mean  to use Assert  ? if you mean something else please enlighten me....thanks
0
 
LVL 10

Expert Comment

by:Hegemon
ID: 33684530
Yes, normally you would use Asserts. Just usual unit test in which you instantiate your EJB classes as POJOs:

MyBean bean = new MyBeanImpl();
0
 

Author Comment

by:cofactor
ID: 33688595
ok..that looks pretty good.

but look   it says   "without requiring the creation of mock objects"  

umm....does it make any sense ?  what this could mean....is it meaningful ?


>>MyBean bean = new MyBeanImpl();

you are really creating instances here  to test.
0
 
LVL 10

Expert Comment

by:Hegemon
ID: 33691666
Can you post the question in full ?

Yes, when you write a unit test, you are supposed to create the object you are testing ?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question