What is best practice for unit testing: include all the cases for the method in one unit test or break them out into separate ones?
Say I have
public int divideTwoInts(int a, int b){...}
And my default test case makes sure that
//Default Case
@Test
public testDivideTwoInts(){
int a = 6;
int b = 3;
int result = 2;
int expResult = divideTwoInts(a, b);
assertEquals(result, expResult);}
so far so good... but, say I want to make sure I handle division by zero - ie testing boundary and bad input cases.
Would I add it as a new unit test as in:
@Test
public testDivisionByZero_DivideTwoInts(){...}
OR as just another batch of code in my existing test?
(Also apologies if this has already been asked - coudn't find it)
Aucun commentaire:
Enregistrer un commentaire