O'Reilly logo

Testing with F# by Mikael Lundin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Your test should never be more than 10 lines of code

Here is one controversial commandment that always takes my students aback when I'm teaching them test-driven development. In F#, this is not a hard requirement and in C# it only brings a healthy restriction on the length of a test.

Because the length of a test is directly proportional with how readable this test is. A longer test will be less readable, and the longer it is the harder it will be to maintain. Instead, I propose that we should have as short tests as possible. The optimal length of a test would be three lines of code. We have the triple A syntax pattern as follows:

  • Arrange
  • Act
  • Assert

Sometimes, you need a few more lines of arrange, in order to set up the prerequisites for the test to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required