Persimmon


Getting Started

An overview of Persimmon, how to download and use.

Creating project(or Getting sample project)

Now create a project and install Persimmon from NuGet (and enable NuGet Package Restore), or download sample project.

Getting Persimmon console runner

Run the command below:

1: 
.\.nuget\NuGet.exe Install Persimmon.Console -OutputDirectory tools -ExcludeVersion

The first step

You can write the tests by using test computation expression and assertion functions.

1: 
2: 
3: 
4: 
5: 
open Persimmon

let ``some variable name`` = test "first test example" {
    do! assertEquals 0 (4 % 2)
}

Executing test

Run the command below:

1: 
.\tools\Persimmon.Console\tools\Persimmon.Console.exe 'input file path'

Omitting test name

Open UseTestNameByReflection module:

1: 
2: 
3: 
4: 
5: 
open UseTestNameByReflection

let ``first test example`` = test {
    do! assertEquals 0 (4 % 2)
}

Testing exceptions

trap computation expression can catch exceptions.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
exception MyException

let ``exception test`` = test {
  let f () =
    raise MyException
    42
  let! e = trap { it (f ()) }
  do! assertEquals "" e.Message
  do! assertEquals typeof<MyException> (e.GetType())
  do! assertEquals "" (e.StackTrace.Substring(0, 5))
}

Parameterized tests

Persimmon supports parameterized tests.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
let ``case parameterize test`` =
  let parameterizeTest (x, y) = test {
    do! assertEquals x y
  }
  parameterize {
    case (1, 1)
    case (1, 2)
    run parameterizeTest
  }

let inputs = [ 2 .. 2 .. 20 ]

let ``source parameterize test`` =
  let parameterizeTest x = test {
    do! assertEquals 0 (x % 2)
  }
  parameterize {
    source inputs
    run parameterizeTest
  }
val ( some variable name ) : obj

Full name: GettingStarted.( some variable name )
val ( first test example ) : obj

Full name: GettingStarted.( first test example )
exception MyException

Full name: GettingStarted.MyException
val ( exception test ) : obj

Full name: GettingStarted.( exception test )
val raise : exn:System.Exception -> 'T

Full name: Microsoft.FSharp.Core.Operators.raise
val typeof<'T> : System.Type

Full name: Microsoft.FSharp.Core.Operators.typeof
val ( case parameterize test ) : obj

Full name: GettingStarted.( case parameterize test )
val parameterizeTest : ('a * 'b -> 'c)
val x : 'a
val y : 'b
val inputs : int list

Full name: GettingStarted.inputs
val ( source parameterize test ) : obj

Full name: GettingStarted.( source parameterize test )
val parameterizeTest : ('a -> 'b)
Fork me on GitHub