Single Statement Unit Tests

Many articles and books have already been written about unit testing patterns and anti-patterns. I want to add one more recommendation which, I believe, can help us make our tests, and our production code, more object-oriented. Here it is: a test method must contain nothing but a single assert.

[image error]Bullet (1996) by Julien Temple

Look at this test method from RandomStreamTest from OpenJDK 8, created by Brian Goetz:

@Test public void testIntStream() { final long seed = System.currentTimeMilli...
1 like ·   •  0 comments  •  flag
Share on Twitter
Published on May 16, 2017 17:00
No comments have been added yet.