Let's say I have 2 methods in a class
public void create(SomeClass objectOfSomeClass) {
//some code to persist in db
}
public SomeClass get(String identifierOfPersistedObjected( {
// some code to query from db
}
Question is- while testing the create method of class, would you use the get method in the test case to check whether the object was persisted? Or would you duplicate the code in the get method and query db directly? This, assuming that we are using the in-memory version of the db for unit testing.
IMHO, the code duplication is better in this case, since it ensures testing in isolation in this case, but would like to know what others think about the 2 options.
Aucun commentaire:
Enregistrer un commentaire