Book Image

Testing with F#

By : Mikael Lundin
Book Image

Testing with F#

By: Mikael Lundin

Overview of this book

Table of Contents (17 chapters)
Testing with F#
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Data-driven testing


One important aspect when doing integration testing is to be able to test with a diversity of data. This might at times render a lot of repetition, for example, we might want to run the same exact test but with other input values. Instead of writing a unique test for each and every test case, you can write a general test and supply the data for the test separately.

In order to demonstrate this, go back to our address register and query it for addresses. This is what our SUT will look like:

type dbSchema = SqlDataConnection<"Data Source=.;Initial Catalog=Chapter05;Integrated Security=SSPI;">

// find an address by a search string
let searchAddress q (db : dbSchema.ServiceTypes.SimpleDataContextTypes.Chapter05) =
    query {
        for address in db.Address do
        where ((address.StreetName.StartsWith q) ||
                (address.StreetNumber = q) ||
                (address.PostalCode.StartsWith q))
        select address
    }

This function will allow you to...