I am currently writing some unit test for my Java 8 code. And I have a problem.
In the code below, you can see 3 test functions the first one returns 6 which is correct. However, the second one does also return 6 even though it should return 16, and the third also return 6 even though it should return 21.
And if I comment out the first function the second returns 16 which is correct. But now the third function is returning 16 instead of 6, where it should return 21.
The code I am testing is a Static Class.
@Test
public void testRun1() {
Integer[][] input = {
{6},
{6, 6},
{5, 6},
{4, 6},
{3, 6},
{2, 6},
{1, 6},
};
int expResult = 6;
int result = BoardingTest.Run(input);
assertEquals(expResult, result);
}
@Test
public void testRun2() {
Integer[][] input = new Integer[][]{
{6},
{6, 6},
{6, 4},
{5, 6},
{3, 8},
{1, 9},
{2, 1},
};
int expResult = 16;
int result = instance.Run(input);
assertEquals(expResult, result);
}
@Test
public void testRun3() {
Integer[][] input = new Integer[][]{
{6},
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5},
{6, 6},
};
int expResult = 21;
int result = BoardingTest.Run(input);
assertEquals(expResult, result);
}
Aucun commentaire:
Enregistrer un commentaire