Reinventing Assertions
beust.com·22h·
Discuss: Hacker News
Flag this post

Reinventing assertions

If you have ever written a test in Java, you are undoubtedly familiar with the Assert class:

Assert.assertEquals(result, expected);

Java 5 introduced the assert keyword, but because it wasn’t enabled by default, the world of testing has continued to use the Assert class.

I’ve always been bothered by the fact that the methods on this class are static, which shouldn’t come as a surprise since getting rid of statics in my test code base was one of the motivating factors I had for creating TestNG.

Over the past years, I have received an increasing number of requests to make assertions more flexible in order to support various scenarios:

  • Logging all the assertions as they are happening, even if they succeed.
  • Accumulating the results of multiple a…

Similar Posts

Loading similar posts...