Leem.fin Leem.fin - 11 months ago 59
Java Question

Junit assert OR condition in my case

In my test case, I get a integer value:

int val = getXXX();

Then, I would like to check if
either equals to 3 or equals to 5 which is ok in either case. So, I did:

assertTrue(val == 3 || val==5);

I run my test, the log shows
is 5, but my above assertion code failed with AssertionFailedError. Seems I can not use
in this way, then, how to check true for OR condition?

Answer Source

ive tried to write quick test:

public void testName() {
    int i = 5;
    junit.framework.Assert.assertTrue(i == 3 || i == 5);


its passing always so i guess there is some inbetween code when your value is changed. You can use

org.junit.Assert.assertEquals(5, i);

to check value - this assertion will print out nice info whats wrong, for example:

Expected :4
Actual   :5