6 people like it.

unit test in VS11 beta

Demo F# unit test in VS11 beta. In VS 2010 unit testing requires a hack whereby you add a c# test project to your solution and add to that project a linked item to the DLL of the F# project with the test methods.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
module TestFsharp

open Microsoft.VisualStudio.TestTools.UnitTesting

type SampleClassType(argument1: int, argument2: int) = 
    /// Get the sum of the object arguments
    member x.Sum = argument1 + argument2
    /// Create an instance of the class type
    static member Create() = SampleClassType(3, 4)

let t = SampleClassType(5, 5)
let y = t.Sum
let z = 0

[<TestClass>]
type TestCaseUtil() =
    [<TestMethod>]
    [<TestCategory("TestFsharp")>]
    [<Description("Assert Not Equal")>]
    member this.AssertNot() =
        Assert.AreNotEqual(5, y)
    [<TestMethod>]
    [<TestCategory("TestFsharp")>]
    [<Description("Assert Equal")>]
    member this.AssertEqual() =
        Assert.AreEqual(10, y)
module TestFsharp
namespace Microsoft
Multiple items
type SampleClassType =
  new : argument1:int * argument2:int -> SampleClassType
  member Sum : int
  static member Create : unit -> SampleClassType

Full name: TestFsharp.SampleClassType

--------------------
new : argument1:int * argument2:int -> SampleClassType
val argument1 : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val argument2 : int
val x : SampleClassType
member SampleClassType.Sum : int

Full name: TestFsharp.SampleClassType.Sum


 Get the sum of the object arguments
static member SampleClassType.Create : unit -> SampleClassType

Full name: TestFsharp.SampleClassType.Create


 Create an instance of the class type
val t : SampleClassType

Full name: TestFsharp.t
val y : int

Full name: TestFsharp.y
property SampleClassType.Sum: int


 Get the sum of the object arguments
val z : int

Full name: TestFsharp.z
Multiple items
type TestCaseUtil =
  new : unit -> TestCaseUtil
  member AssertEqual : unit -> 'a
  member AssertNot : unit -> 'b

Full name: TestFsharp.TestCaseUtil

--------------------
new : unit -> TestCaseUtil
val this : TestCaseUtil
member TestCaseUtil.AssertNot : unit -> 'b

Full name: TestFsharp.TestCaseUtil.AssertNot
member TestCaseUtil.AssertEqual : unit -> 'a

Full name: TestFsharp.TestCaseUtil.AssertEqual
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/b1
Posted:12 years ago
Author:Jack Fox
Tags: testing