Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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

The false security of code coverage

When doing test automation, you can use a tool that will tell you how large a part of your code is covered by tests. This may seem like a good idea at first glance, but does have some hidden dangers.

The following image shows the code coverage tool, NCover:

The false security of code coverage

The code coverage report will show you what code was traversed and how many times, but it's a false assumption that the report will tell you what was tested. How many times is it required that a test pass a line of code in order to call it covered? Consider the following example:

open NUnit.Framework
open FsUnit

// System Under Test
let rec fibonacci = function
    | n when n < 2 -> 1
    | n -> fibonacci (n - 2) + fibonacci (n - 1)

let fibonacciSeq x = [0..(x - 1)] |> List.map fibonacci

[<Test>]
let returns_correct_result () = 
    fibonacciSeq 5 |> should equal [1; 1; 2; 3; 5]

The test is written only to traverse all the code in one go. It doesn't have a clear purpose...

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