Programming languages give us a lot of expressive power.

this flexibility comes at the cost of increased complexity

simplicity is more important than flexibility in tests

Tests can avoid complexity by stating their inputs and outputs directly rather than computing them

Does this test look correct to you?

@Test public void shouldNavigateToPhotosPage() { String baseUrl = "http://plus.google.com/" ; Navigator nav = new Navigator(baseUrl); nav.goToPhotosPage(); assertEquals(baseUrl + "/u/0/photos" , nav.getCurrentUrl()); }

what happens if we simplify the test by inlining the variable?

@Test public void shouldNavigateToPhotosPage() { Navigator nav = new Navigator( "http://plus.google.com/" ); nav.goToPhotosPage(); assertEquals( "http://plus.google.com//u/0/photos" , nav.getCurrentUrl()); // Oops! }

After eliminating the unnecessary computation from the test, the bug is obvious

when a test adds more operators or includes loops and conditionals, it becomes increasingly difficult to be confident that it is correct.

whereas production code describes a general strategy for computing outputs given inputs, tests are concrete examples of input/output pairs

When tests do need their own logic, such logic should often be moved out of the test bodies and into utilities and helper functions