Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this a stub, mock, or fake?

 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic