Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Testing with f#

You're reading from   Testing with f# Deliver high-quality, bug-free applications by testing them with efficient and expressive functional programming

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781784391232
Length 286 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mikael Lundin Mikael Lundin
Author Profile Icon Mikael Lundin
Mikael Lundin
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. The Practice of Test Automation FREE CHAPTER 2. Writing Testable Code with Functional Programming 3. Setting Up Your Test Environment 4. Unit Testing 5. Integration Testing 6. Functional Testing 7. The Controversy of Test Automation 8. Testing in an Agile Context 9. Test Smells 10. The Ten Commandments of Test Automation Index

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 run. Assert might need an extra line to help extract the result we got from running the test.

The act section of the test should always be only one line of code. This is important to keep the test cohesive. If the act only consists of one line of code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image