TestNG Confusion

I love me some TestNG, yes I do, but recently it went completely haywire on a test…


java.lang.AssertionError:
Expected :null
Actual :null

at org.testng.Assert.fail(Assert.java:89)
at org.testng.Assert.failNotSame(Assert.java:485)
at org.testng.Assert.assertNull(Assert.java:421)
at org.testng.Assert.assertNull(Assert.java:410)
at com.comapny.tests.SimpleTest.testExpectedNull(SimpleTest.java:31)

Expected null, actual null? Well those look the same, how can they not be? Simple. I was doing a conversion with String.valueOf.

defaultValue = String.valueOf(defaultValue);

The valueOf(null) is the literal string “null”, something that looks the same in any printed representation. Checking for an actual null, instead of converting it, solved the problem. Like so:

defaultValue = (null==defaultValue) ? null : String.valueOf(defaultValue);

Related Posts:

This entry was posted in Programming and tagged , , , . Bookmark the permalink.

Comments are closed.