Nikos
Nikos

Reputation: 7551

Making F# Test case methods public for unit testing with 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?

Upvotes: 6

Views: 585

Answers (2)

pad
pad

Reputation: 41290

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)

Upvotes: 11

Phillip Trelford
Phillip Trelford

Reputation: 6543

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)

Upvotes: 7

Related Questions