Monday, November 10, 2014

Destructive habits

    I have been using JUnit for quite a long time. I have recently done some coding with TestNG and I was a little bit shocked when I saw the assertion exception for the first time.
 The following assertion is perfectly valid in JUnit:

org.junit.Assert.assertEquals("expected", "actual");

and the exception:

Exception in thread "main" org.junit.ComparisonFailure: expected:<[expected]> but was:<[actual]>

Pretty similar line in TestNG:
 
org.testng.Assert.assertEquals("expected", "actual");
 
produces:
 
Exception in thread "main" java.lang.AssertionError: expected [actual] but found [expected]

As seen, the order of the arguments is different in TestNG. We should have written:
org.testng.Assert.assertEquals("actual", "expected");
Although the creators of TestNG may have had nothing in common with JUnit folks, I was a little bit shocked when I saw the stack trace for the first time. Even if sometimes something seems to be obvious it may be not be true in real and you may be wrong because of force of habit.

No comments :

Post a Comment