umitems umitems - 1 year ago 48
Android Question

How to run all test cases ,Even the previous test cases are wrong

I just begin to try on JUnit. I have created some test cases. However, the test case will stop when I found any wrong test case. I want to run through every test case even there are many wrong test case.


assertEquals ( "this test case will be shown", ( 1,2 ),3 );
assertEquals ( "this first wrong test case will be shown", ( 1, 2 ), 4 );
assertEquals ( "this first wrong test case **won't be shown**", ( 1, 2 ), 4 );

I want to let the third this case be run (show that it is wrong)

Answer Source

Assertions are not test cases. A failed assertion will throw an exception which if uncaught will propagate up and the rest of the test will not be executed.

Your solution is to put each of these assertions into different tests.

Also a side note, usually the first argument to the assertion is the expected value so I'd swap the inputs.

public void correctAddition(){

public void wrongAddition(){
        //test will fail

public void wrongAddition2(){
        //test will also fail