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
  }
namespace Persimmon
val ( some variable name ) : TestCase<unit>
val test : name:string -> TestBuilder
val assertEquals : expected:'a -> actual:'a -> AssertionResult<unit> (requires equality)
module UseTestNameByReflection

from Persimmon.Syntax
val ( first test example ) : TestCase<unit>
val test : TestBuilder
exception MyException
val ( exception test ) : TestCase<unit>
val f : (unit -> int)
val raise : exn:System.Exception -> 'T
val e : exn
val trap : TrapBuilder
custom operation: it ('b)

Calls TrapBuilder.It
property System.Exception.Message: string with get
val typeof<'T> : System.Type
System.Exception.GetType() : System.Type
property System.Exception.StackTrace: string with get
System.String.Substring(startIndex: int) : string
System.String.Substring(startIndex: int, length: int) : string
val ( case parameterize test ) : seq<TestCase<unit>>
val parameterizeTest : ('a * 'a -> TestCase<unit>) (requires equality)
val x : 'a (requires equality)
val y : 'a (requires equality)
val parameterize : ParameterizeBuilder
custom operation: case ('a)

Calls ParameterizeBuilder.Case
custom operation: run ('a -> TestCase<'b>)

Calls ParameterizeBuilder.RunTests
val inputs : int list
val ( source parameterize test ) : seq<TestCase<unit>>
val parameterizeTest : (int -> TestCase<unit>)
val x : int
custom operation: source (seq<'a>)

Calls ParameterizeBuilder.Source
Fork me on GitHub