1

I found in a project i'm about to contribute with some external lib, that for testing purpose they set up a mock database manager. However what this database manager does, is creating an in-memory database and working with it. This is for testing purpose.

The framework used is Jmockit.

I try to find out how i could reproduce that in scalamock, but could not figure out.

Here how this is set up in jmockit:

/**
 * Mocks a DatabaseManager so unit tests can be run without a real DB connection
 * The code is basically the same as the original DatabaseManager but it
 * establishes a connection to an in-memory database.
 *
 * @author pvillega
 */
@MockClass(realClass = DatabaseManager.class)
public class MockDatabaseManager {...}

Is there anything that could support that in scalamock. I know this is related to how the all application has been developed. Especially how they used or did not used dependency injection. But nevertheless we have to deal with legacy code sometime :) (most of the time)

The only thing i see is writing all the function of a stub. A - However that is just not nice. B - Also it is not a full class that can retain state. So everything would have to be manage in the enclosing class that is creating the stub. c - Again, legacy code do a lot of funny things inside the class, so i would have to recreate all the code and etc... d - I would appreciate to reuse what they MockDatabaseManager.

Any advise?

MaatDeamon
  • 9,532
  • 9
  • 60
  • 127

0 Answers0