jeudi 28 janvier 2016

Testing multiple public methods that calls the same private method

I'm trying to figure out whether it's an API design flaw, it is actually OK, or the SRP is being violated.

I'm having 2 public methods initialize() and onListRefresh(). Both of them call the same private method updateList(). The only difference between both of them is that initialize() also check for a null argument to throw an exception.

The issue is that in order to test both public methods, I practically have to copy paste the same mocks, stub, expectations and assertions, which are all for what happens on the private method; And it feels wrong. So which one is it:

  1. Is there a flaw in the public API design?
  2. It's alright, that's how it's supposed to be.
  3. You're violating SRP by using initialize() to do both checking for an argument AND calling updateList()

Aucun commentaire:

Enregistrer un commentaire