aspose file tools*
The moose likes Testing and the fly likes How to use dummy values in Junit when values from database are required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to use dummy values in Junit when values from database are required" Watch "How to use dummy values in Junit when values from database are required" New topic
Author

How to use dummy values in Junit when values from database are required

Laryssa Fernandes
Greenhorn

Joined: Apr 14, 2011
Posts: 5
I have to write Junit test cases for some code. This code uses a database that I don't have. I have to write test cases for methods that call methods from other classes that access the database. Is it possible for me to somehow cause the methods in the other classes to return some dummy values when values from the database are required? Without changing any of the code...
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Create a class that extends your database class, pass it in the constructor.

Somethig like this:

You also could use JUnit with HSQLDB that will works as a fake database: JUnit with HSQLDB, JPA and Hibernate.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use dummy values in Junit when values from database are required
 
Similar Threads
Application Testing tools and tests
help me in writing a unit test case for the given servlet
Organising output from methods
JUnit tests on the database CRUD functions.
Scope of JUnit testing