Reputation: 727
I'm learning F# recently. Today I wrote some code and tried to add unit tests.
I planed to create two projects, one is for code and the other is for test.
So I created a new solution called DataLab
with a project called Source
in Visual Studio 2015 Community. Then I added another project called Test
.
The structure is like below:
Solution 'DataLab'
Source
Queue.fs
Test
QueueTest.fs
Queue.fs
is:
namespace DataLab
type Queue<'a> = Queue of 'a list * 'a list
module Queue =
let init<'a> : Queue<'a> = Queue ([], [])
QueueTest.fs
is:
namespace DataLab.Test
module QueueTest =
open DataLab
open FsUnit
open NUnit.Framework
[<Test>]
let ``test Init`` () =
let expected : Queue<int> = Queue ([], [])
Queue.init<int> |> should equal expected
Then VS warned me about the open
statements in QueueTest.fs
. One of the three was:
The namespace or module 'FsUnit' is not defined
So I added reference to Source
project for Test
project. I also installed FsUnit
via NuGet for Test
project.
I didn't install NUnit
because it's a dependency of FsUnit
.
And I didn't install FsUnit
for Source
project because Source
does not need testing libraries.
I wanted to make it similar to <scope>test</scope>
thing for JUnit dependency in maven.
I built the whole solution successfully.
When I run my test in 'Test Explorer' (I also installed the 'NUnit3 Test Adapter' extension), I got error below:
System.MissingMethodException : Method not found: 'DataLab.Queue`1<!0> DataLab.Queue`1.NewQueue(Microsoft.FSharp.Collections.FSharpList`1<!0>, Microsoft.FSharp.Collections.FSharpList`1<!0>)'.
After some random try, I got the test executed successfully by installing FsUnit
to Source
project too.
I have a theory about this problem.
I installed FsUnit 2.0.0
which has a dependency of FSharp.Core (>= 3.1.2.5)
. So FSharp.Core 3.1.2.5
has also been installed to my Test
project. And this polluted my Test.fsproj
file.
I have below lines in Test.fsproj
:
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\packages\FSharp.Core.3.1.2.5\lib\net40\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
Meanwhile the Source
project still using VS 2015 built-in F#, whose version is 4.0+ . So the two versions of F# conflict.
But I don't know how to prove it or how to fix it.
Upvotes: 0
Views: 250