This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Testing and the fly likes Is this a stub, mock, or fake? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Is this a stub, mock, or fake?" Watch "Is this a stub, mock, or fake?" New topic
Author

Is this a stub, mock, or fake?

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

I'm working on a client/server application that uses a class DbAccess to manage a database connection. The basic interface:



That's not exactly how I would design it, but for now I need to live with it.

The openConnection() method gets a connection from a DataSource configured and maintained by the app server. I've made a subclass that overrides openConnection() to make a one-off connection to the database via the DriverManager instead, and I'm using this for various outside-of-the-container testing. Would I call this subclass a fake, stub, or mock? I think fake is the right term, but I'd like an expert opinion.

Let's say now that I also have a subclass of DbAccess that returns a fake (or mock or stub) ResultSet, which reads data out of text files and bypasses the database altogether. I'm struggling coming up with good names for these classes. How about DbAccessConnectionFake and DbAccessDataFake / ResultSetDataFake? I'm not liking that a lot.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is this a stub, mock, or fake?