• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Laryssa Fernandes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic