Skip to content

Gold Master Testing

Jason Kerney edited this page Sep 28, 2015 · 8 revisions

What is Gold Master Testing

Gold Master Testing is a process where the expected result is an artifact that a human understands and acknowledges as correct. This artifact is the "Gold Standard" or "Gold Master". It usually lives in a separate file from the unit tests.

Benefits

  • Humans are great at pattern recognition. This type of testing takes advantage of that.
  • Increases understandably of a failure by showing a full picture of the differences.
  • Enforces Single Responsibility of test code, since expected result and test code are in different files.

Reporters

Reporters are types that are used to display why a test has failed to the human. Reporters allow for the system to capitalize on the ability of Humans to recognize patterns.

BE AWARE If using the command line runner then you will have to use --ur for reporters to be used.

Configuring Reporters

Before you can see your results you will need a bit of config code. This code can be located any-where in your project. The findFirstReporter function finds the first reporter checks to see if a reporter of the specified type will run on the current system. If so it returns that reporter. If not it checks the next. If all fail, it then returns a reporter which echoes the Gold Standard's file name to the Console. All reporters listed in the return value Reporters are used.

Start

open FeldSpar.Framework
open ApprovalTests.Reporters

Code

let ``Setup Global Reports`` = 
    Config(fun () -> 
    { 
        Reporters = [
                        fun _ -> 
                                Searching
                                    |> findFirstReporter<Reporters.DiffReporter>
                                    |> findFirstReporter<Reporters.WinMergeReporter>
                                    |> findFirstReporter<Reporters.NotepadLauncher>
                                    |> unWrapReporter
                                        
                        fun _ -> Reporters.ClipboardReporter() :> Core.IApprovalFailureReporter;

                        fun _ -> Reporters.QuietReporter() :> Core.IApprovalFailureReporter;
                    ]
    })

Writing Tests

The verification of Gold Master tests all start with check and then against some kind of standard. The two most common are checkAgainstStringStandard, checkAllAgainstStandard, and checkAgainstStandardObjectAsString

Gold Master tests make use of the env or environment parameter which allows you to change some of the settings for your tests.

Start

open FeldSpar.Framework
open FeldSpar.Framework.Verification
open FeldSpar.Framework.Verification.ApprovalsSupport
open ApprovalTests

Code

type Color = | White | Brown | Black | TooCool
type TestingType =
    {
        Name : string;
        Age:int;
        Dojo:string * Color
    }

let ``A test to check verification`` = 
    Test(fun env ->
            let itemUnderTest = 
                sprintf "%A%s"
                    ({
                        Name = "Steven";
                        Age = 38;
                        Dojo = ("Too Cool For School", TooCool)
                    }) "\n"

                itemUnderTest |> checkAgainstStringStandard env
        )

let ``This is a Combinatory Gold Standard Testing`` =
    Test(fun env ->
        let names = ["Tom"; "Jane"; "Tarzan"; "Stephanie"]
        let amounts = [11; 2; 5;]
        let items = ["pears";"earrings";"cups"]

        let createSentance item amount name = sprintf "%s has %d %s" name amount item

        createSentance
            |> calledWithEachOfThese items
            |> andAlsoEachOfThese amounts
            |> andAlsoEachOfThese names
            |> checkAllAgainstStandard env
    )

Clone this wiki locally