2

Is there anyway to assert that,

actual int value = expected int value not equal to 0

Something like,

Assert.assertEquals(length, 0);
3
  • can you please give some example? Feb 24, 2016 at 12:05
  • Are you referring to this: Assert.assertTrue(actIntValue==expIntValue && expIntValue > 0); Mar 25, 2016 at 14:11
  • Are you trying to check two things? That actual value = expected value and that actual value <> 0?
    – dzieciou
    May 28, 2016 at 14:49

4 Answers 4

3
public static void assertEquals(int actual,
                                int expected,
                                java.lang.String message)

Asserts that two ints are equal. If they are not, an AssertionFailedError, with the given message, is thrown. Parameters: actual - the actual value expected - the expected value message - the assertion error message

1
2

The TestNG Assert documentation describes a function assertNotEquals

Assert.assertNotEquals(length, 0);

This does what you want I guess, if not you can also check with assertEquals with some extra code.

Pseudo code:

result = false
if (length == 0 ) {
  result = true
}
Assert.assertEquals(result, false)
0

I would use assertThat instead of simple assertEquals or assertNotEquals for the reasons described on Stackoverflow:

assertThat(actual, is(not(equalTo(expected)));
assertThat(actual, is(not(equalTo(0)));
0

Try to use assertTrue in TestNG.

Assert.assertTrue(length > 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.