dimanche 31 mai 2015

Testing multiple classes with 1 test

Say I have an interface with 2 classes that both implement it. So we have interface I, with classes A and B. For these 2 classes, we need to test the same implemented function, doSomething() with JUnit4. There's some dependencies, so we're using Mockito. An example test looks like:

@Mock private dependantClass d;

@Test
public void test() {
    A.doSomething();
    verify(d).expectedBehavior();
}

I've written the test suite for A (4 tests), no problems. However, now I have to restructure the test suite so I can execute the same test class on both A and B objects. For this, I should use a parallel class hierarchy.

This has left me stumped. I've tried using the @Parameters annotation, but this gives me the error that I have too many input arguments. I've tried making a super test class that both ATest and BTest extend from, but I'm guessig I'm not doing it right because I get nullpointer exceptions.

Actually copying all test cases and just changing A to B passes all the tests, that's to say that these 2 classes do the same. I realize that that sounds like faulty design, and to be honest, it probably is. However, I do not have the possibility to actually alter the code, I just have to test it.

Am I just doing things wrong? How should I implement this?

Aucun commentaire:

Enregistrer un commentaire