• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Confused with Best pratices of JUnit

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The JUnit best pratice states that :

It does not depend on the runtime environment (container) provided by an application server

Then how can I obtain Database connection for testing DB operations.

Because as per the statement I can't use a LOOKUP mechanism inside my Test class

Please help me .
 
author & internet detective
Posts: 41125
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It says JUnit doesn't depend on anything. It doesn't say that you can't write tests that do.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response.

Please clarify if it will be a good approach to use DataSource lookup inside the Testclass , as i need to test the DAO operations.


Thanks in advance
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please tell me should i run a TestCase with the suppourt of a Container ??

Or seperetely without using any container support ?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:It says JUnit doesn't depend on anything. It doesn't say that you can't write tests that do.



Jeanne , i have a DataSource configured in weblogic, shall i use jndi lookup inside a Testmethod directly ??
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anybody
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Out of Box - no container

if you are using Spring in your application you can use spring mock where you dont need a container it will mock every thing that requires to run an web application environment including dao layer.

if you are using maven you can use this in pom.xml to download mock



And for datasource initialization there another way to do it. Use apache DBCP
if you are using maven you can use this in pom.xml to download dbcp
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2</version>
</dependency>

And in your mock applicationContext.xml put this




2. Using container
Use cactus instead of Junit
cactus is just superset of junit.

One more thing to give you a very clear picture follow the blog of The Arsenalist, very nice article. I adapted his ideas when i was developing junit test case for Struts2 + spring base application.

http://arsenalist.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/

Thanks
Jack
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks , but the problem is that i am not using spring and weblogic container is heavily dependent.
 
Jeanne Boyarsky
author & internet detective
Posts: 41125
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:

Jeanne Boyarsky wrote:It says JUnit doesn't depend on anything. It doesn't say that you can't write tests that do.



Jeanne , i have a DataSource configured in weblogic, shall i use jndi lookup inside a Testmethod directly ??


What happened when you tried it?
 
Jeanne Boyarsky
author & internet detective
Posts: 41125
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:anybody


Remember to be patient. Some people check the forums only once a day; or not at all on weekends. Implying you are mad because you didn't get a reply right away is not the way to get someone to help you. Remember the time spent by a volunteer depends on their mood. I could take the time to speculate about datasources. But when someone tells me they are mad that I didn't reply quickly enough, I don't feel very motivated to. Which leads me to my more minimal answer. After all, I could use my time to help someone who is nicer about requests and fleshes out the question.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What happened when you tried it?



It perfectly works , but don't know will it be a good practice to use container dependants for writing TestCases .
 
Jeanne Boyarsky
author & internet detective
Posts: 41125
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Pavan wrote:

What happened when you tried it?



It perfectly works , but don't know will it be a good practice to use container dependants for writing TestCases .


As you don't have an alternative, it hardly matters whether it is good practice.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jeanne , replies from Java Ranch experts adds confidence to me to continue with my work.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic