My database of choice is MongoDB. I am writing a data-level API for an abstract implementation detail from client applications, that is, I essentially provide a single open interface (an object that acts as an IDL).
I test my logic when I enter TDD. Before each unit test, the @Before method is @Before to create a singleton database, after which, when the test completes, the @After method is @After to delete the database. This helps increase independence from unit tests.
In almost all unit tests, that is, when executing a contextual query, some kind of insertion logic is required, which must happen before hand. My open interface provides an insert method - however, it seems incorrect to use this method as the predecessor logic for each unit test.
Actually, I need some kind of mocking mechanism, but I didn’t have much experience in mocking frameworks, and it seems that Google is not returning anything from the mocking frame that can be used with MongoDB.
What do others do in these situations? That is, how are people unit test code that interacts with the database?
In addition, my open interface connects to the database defined in the external configuration file - it seems wrong to use this connection for my unit testing - again, a situation that would benefit from some kind of ridicule?
java unit-testing junit mongodb morphia
wulfgarpro Sep 14 '11 at 9:18 2011-09-14 09:18
source share