dimanche 21 décembre 2014

How to implement multiple test cases for the same exception in JUnit 4

i'm implementing some tests in JUnit 4 and i don't know to code multiple tests for the same exception.


When the expected output is, for example, a float i initialize the array with the inputs and the expected results, then i populate the results' array and finally i use assertArrayEquals(). It looks like this:



@Test
public void testing() throws Exception {
float[] inputs = {10.24f,20.23f};
float[] expectedResults = {10.2f,20.2f};
float[] results = new float[inputs.length];


for (int i=0;i<inputs.length;i++) {
results[i]=methodBeingTested(inputs[i]);
}

assertArrayEquals(expectedResults, results);

}


I want to do this but for an exception. There must be a better way than creating a method for the each test case where an Exception is expected. Can anyone enlighten me please?


Aucun commentaire:

Enregistrer un commentaire