Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making F# Test case methods public for unit testing with Nunit

Tags:

f#

nunit

I'm using F# to write my test methods but Nunit complains that the methods are non public.

    namespace Test

open NUnit.Framework

type public Test() = 

    [<Test>]
    let testIt () =

        Assert.AreEqual(10,10)

what do I need to change?

like image 619
Nikos Avatar asked Jan 30 '13 16:01

Nikos


2 Answers

Since let bindings are private to the parent type, you have to use member instead:

namespace Test

open NUnit.Framework

[<TestFixture>]
type public Test() = 

    [<Test>]
    member x.testIt() =
        Assert.AreEqual(10, 10)

If you don't need complicated setups, using module-level let bindings directly should be preferable:

module Test

open NUnit.Framework

[<Test>]
let testIt() = Assert.AreEqual(10, 10)
like image 158
pad Avatar answered Nov 15 '22 10:11

pad


You can put F# test cases in a module to make them public and visible to NUnit:

module Tests

open NUnit.Framework

let [<Test>] ``10 should equal 10`` () = Assert.AreEqual(10,10)
like image 45
Phillip Trelford Avatar answered Nov 15 '22 12:11

Phillip Trelford