Results 1 to 4 of 4
  1. #1
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Couple questions about unit testing in Java

    Used I create a database connection in the class being tested? The reason I ask is if I test the class it would make changes to the database. Should I use a test database, and if so, how would I tell the class to do this? Should I use mock objects to simulate a database? If so wouldn't this be rather hard to set up all the tables, relationships, etc. and data necessary to do this? Any help on these questions would be appreciated! :)

  2. #2
    christopherx is offline Member
    Join Date
    Oct 2011
    Posts
    92
    Rep Power
    0

    Default Re: Couple questions about unit testing in Java

    If you don't want to change the original database because it has important information on it, then for the love of God don't go near it! Weird and wonderful things can happen when we run testing. If I were you, I would create a database with the same columns; perhaps even an identical copy of the original database, and use that. That way, the program is working with the database it would always be working with, without putting information at risk.

    On another note, if you're not testing database access than there's no point :P

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,861
    Rep Power
    19

    Default Re: Couple questions about unit testing in Java

    Exactly.
    If this is unit testing then you shouldn't really be looking at the database.
    It should be stubbed (mocked) out.
    That's part of integration testing.

  4. #4
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default Re: Couple questions about unit testing in Java

    Quote Originally Posted by christopherx View Post
    If you don't want to change the original database because it has important information on it, then for the love of God don't go near it! Weird and wonderful things can happen when we run testing. If I were you, I would create a database with the same columns; perhaps even an identical copy of the original database, and use that. That way, the program is working with the database it would always be working with, without putting information at risk.

    On another note, if you're not testing database access than there's no point :P
    Sorry it's been awhile since I worked in Java. I kinda forgot how to handle this since I haven't done it in awhile. I've been working in PHP and using MVC frameworks and you have to do to test up a test db in that is change a config file. Thank you both, I figured out what I need to do. :)

Similar Threads

  1. Getting a nullpointer with unit testing
    By aborgeld in forum New To Java
    Replies: 4
    Last Post: 04-16-2011, 02:06 PM
  2. Couple questions about Java
    By theadolescent in forum New To Java
    Replies: 3
    Last Post: 05-19-2010, 02:13 AM
  3. XML to JSP Unit Testing
    By Abder-Rahman in forum Advanced Java
    Replies: 2
    Last Post: 02-15-2009, 12:35 AM
  4. Unit testing Java EE 5 applications
    By tpbkl in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-23-2008, 02:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •