2

Is there anyway to assert that,

actual int value = expected int value not equal to 0

Something like,

Assert.assertEquals(length, 0);
  • can you please give some example? – Jeevan Bhushetty Feb 24 '16 at 12:05
  • Are you referring to this: Assert.assertTrue(actIntValue==expIntValue && expIntValue > 0); – Mrunal Gosar Mar 25 '16 at 14:11
  • Are you trying to check two things? That actual value = expected value and that actual value <> 0? – dzieciou May 28 '16 at 14:49
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

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, privacy policy and cookie policy

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