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

Asserting only one thing in your test


Let us take a look at the following code:

// don't
[<Test>]
let ``username and password cannot be empty string`` () =
    // arrange
    let credentials = Credentials(System.String.Empty, System.String.Empty)

    // act
    let result = validate(credentials)

    // assert
    result |> should contain UserNameEmpty
    result |> should contain PasswordEmpty

// do
[<Test>]
let ``username cannot be empty string`` () =
    // arrange
    let credentials = Credentials(System.String.Empty, "secret")

    // act
    let result = validate(credentials)

    // assert
    result |> should contain UserNameEmpty

// do
[<Test>]
let ``password cannot be empty string`` () =
    // arrange
    let credentials = Credentials("user", System.String.Empty)

    // act
    let result = validate(credentials)

    // assert
    result |> should contain PasswordEmpty

Cohesion in your code means that the function will do one and only one thing...