6 people like it.
Like the snippet!
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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
|
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 t2 = SampleClassType(6, 6)
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)
//note each TestClass cannot contain the same unique signature more than once
//even if you are testing a method in a different object
[<TestClass>]
type TestCaseUtil2() =
[<TestMethod>]
[<TestCategory("TestFsharp")>]
[<Description("Assert Equal2")>]
member this.AssertEqual() =
Assert.AreEqual(12, t2.Sum)
|
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 t2 : SampleClassType
Full name: TestFsharp.t2
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
Multiple items
type TestCaseUtil2 =
new : unit -> TestCaseUtil2
member AssertEqual : unit -> 'a
Full name: TestFsharp.TestCaseUtil2
--------------------
new : unit -> TestCaseUtil2
val this : TestCaseUtil2
member TestCaseUtil2.AssertEqual : unit -> 'a
Full name: TestFsharp.TestCaseUtil2.AssertEqual
More information