This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Testing with Database connections - help needed

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a application with struts framework which has a DAO class, a bussiness object class. i am using strutstestcase for testing the struts app. but when it gets connected to the DAO(which has lots of session objects getting connected to the DB), the tests donot run. It gives a nullpointerexception. i guess this should be a in-container testing. can anyone give me an idea of which would be the best tool for testing this type of application. Please reply soon.
 
author & internet detective
Posts: 40797
829
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
Betsy,
You have a few choices:
1) Unit tests the DAOs/business object class independently via pure JUnit.
2) Use a tool like StrutsTestCase or Cactus to run your Struts actions in container.
3) Use a tool like HTMLUnit to test your URLs without a browser.
4) Use a tool like Selenium to test your URLs through a browser.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jeanne,

your first point - test the dao's via pure junit requires clarification as the dao class has a lot of session objects which require servletcontext. can this scenario be tested via pure junit? i have tried still i get the same error. can you please help me in understanding how to test this scenario.
 
Jeanne Boyarsky
author & internet detective
Posts: 40797
829
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
Betsy,
You could mock out the servlet context or refactor your code to reduce the dependencies on the context. In the long run, the later is useful as makes your code more testable and maintainable.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i am getting the following error while testing database connections.

junit.framework.AssertionFailedError: Exception in constructor: testhasOAVRole (java.lang.NullPointerException
at com.gm.bpd.common.transaction.Session.connect(Session.java:69)
at com.gm.bpd.common.transaction.Session.<init>(Session.java:35)
at com.gm.bpd.admin.dao.testACLCUDDAO.<init>(testACLCUDDAO.java:15)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:131)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:399)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
)
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


please find the class below.





Please help me resolve ASAP

[edited to add code tags]
[ April 16, 2008: Message edited by: Jeanne Boyarsky ]
 
Jeanne Boyarsky
author & internet detective
Posts: 40797
829
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
I think the problem is in this code. Does it print an error message?

You really should throw an exception, not just print the exception out. This way, it won't fail later with a null pointer. (Also the nested try/catch blocks don't do anything. You only need one level.)

 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YEs i am getting a connectException. what does this mean ?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means your code is trying to connect to a database but fails in doing that. Is there a database? Do you intend to connect to an actual database? What does the ConnectionException say?
reply
    Bookmark Topic Watch Topic
  • New Topic