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

Structuring your tests


The most basic aspect of unit testing is figuring out how to structure your tests. The most common way to structure when writing tests after code is to mimic the namespace hierarchy for your system under a test in another Visual Studio project.

We write our class as follows:

namespace Company.System.BL.Calculators
{
    public class PriceCalculator
    {
        public double GetPrice(object order)
        {
            return .0;
        }
    }
}

Then, our test would look like the following:

namespace Company.System.Tests.BL.Calculators
{
    public class PriceCalculatorTests
    {
        [Test]
        public void GetPriceShould()
        {
            // ...
        }
    }
}

Notice the differences in namespaces and naming conventions. This is a very common way to structure tests because it scales up to very large projects and is pretty straightforward.

It is clear that code is written before the tests, as the test names and hierarchy are directly proportional to the...