fsunit

FsUnit `should equal` fails on `Some []`

て烟熏妆下的殇ゞ 提交于 2019-12-31 00:55:07
问题 When I run this FsUnit test with NUnit 2.6.3, let f xs = Some (List.map ((+) 2) xs) [<Test>] let test() = f [] |> should equal (Some []) I get: Result Message: Expected: <Some([])> But was: <Some([])> Result StackTrace: at FsUnit.TopLevelOperators.should[a,a](FSharpFunc`2 f, a x, Object y) The test fails even though the Expected and Actual in the message are the same. What happened? 回答1: The reason is that FsUnit uses untyped mechanism under the hood so Expected is inferred as object by the

How do I implement multiple argument generation using FsCheck?

拟墨画扇 提交于 2019-12-23 22:40:03
问题 How do I implement multiple argument generation using FsCheck? I implemented the following to support multiple argument generation: // Setup let pieces = Arb.generate<Piece> |> Gen.filter (isKing >> not) |> Arb.fromGen let positionsList = Arb.generate<Space list> |> Arb.fromGen I then used these arguments to test the behavior of a function that's responsible for generating move options for a given checker: // Test Prop.forAll pieces <| fun piece -> Prop.forAll positionsList <| fun

MissingMethodException when testing a function that takes a function parameter

无人久伴 提交于 2019-12-18 08:46:27
问题 I am using FsUnit 2.1 (with NUnit 3.2) to write tests for an F# project. Here is a simple module: namespace Library1 module LibraryFunctions = let Execute f1 = f1() let Id x = x And here are my tests: namespace Tests open FsUnit open NUnit.Framework open Library1 [<TestFixture>] type Tests() = [<Test>] // Passes member x.``LibraryFunctions.Id should return the value``() = LibraryFunctions.Id 42 |> should equal 42 [<Test>] // Fails member x.``LibraryFunctions.Execute should return the result

FsUnit: Unable to test portable library due to it and test project having different F#.Core versions

我们两清 提交于 2019-12-12 04:27:17
问题 I have a Portable Library, for which the FSharp.Core version is 3.7.4.0 . Installing (in the Unit Test project) FsUnit installs, as a dependency, FSharp.Core version 3.1.2.5 . Due to this, using the portable library's functions in my Unit Test project, for example: module StammaTests.PieceTests open Stamma open NUnit.Framework open FsUnitTyped [<Test>] let ``Testing a Basic function`` () = Piece.toChar Black King |> shouldEqual 'k' yields error: Result Message: System.IO.FileLoadException :

Why can't the NUnit Test Adapter find my FsUnit tests?

大城市里の小女人 提交于 2019-12-10 17:17:38
问题 I'm using Visual Studio Professional 2015 and I have version 2.0.0.0 of the NUnit Test Adapter installed. It doesn't discover any tests on building the following code: namespace SmallestDivisibleIntegers module Core = let f n = [2..4] |> List.map (fun x -> x + n - n % x) module Tests = open FsUnit open NUnit.Framework open Core [<Test>] let ``Correct answers`` () = f 1 |> should equal [2; 3; 4] f 4 |> should equal [6; 6; 8] f 43 |> should equal [44; 45; 44] f 123 |> should equal [124; 126;

How to properly test Exceptions with FsUnit

房东的猫 提交于 2019-12-08 15:48:00
问题 I'm trying to figure out how to properly test exceptions with FsUnit. Official documentation states, that to test for exceptions I have to right something like this: (fun () -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception> But, if I don't mark my test method with [<ExpectedException>] attribute it will always fail. Sounds reasonable because if we want to test for exceptions we have to add such attribute in C# + NUnit. But, as long as I've added this attribute it doesn't

Comparing Discriminated Unions

◇◆丶佛笑我妖孽 提交于 2019-12-07 06:13:37
问题 I'm a newbie to F# and I'm playing around with FParsec. I would use FParsec to generate an AST. I would like to use FsUnit to write some tests around the various parts of the parser to ensure correct operation. I'm having a bit of trouble with the syntax (sorry, the exact code is at work, I can post a specific example later) so how exactly could one compare two discriminated unions (one the expected, the other the actual result)? Could someone provide a tiny code example using FsUnit (or

Parameterized tests in f# - This is not a valid constant expression

巧了我就是萌 提交于 2019-12-07 05:02:12
问题 For some reason when passing arguments to the test via TestCase attrubute, I get the following error message about the first argument, which in this case is an array: This is not a valid constant expression or custom attribute value module GameLogicTest = open FsUnit open NUnit.Framework open GameLogic.Examle // This is not a valid constant expression or custom attribute value [<TestCase( [| 1; 2; 3 |], 3, 1,1)>] let ``let example.`` (a, m, h, c) = a |> proof1 m |> should equal (h,c) But when

Comparing Discriminated Unions

ⅰ亾dé卋堺 提交于 2019-12-05 08:53:30
I'm a newbie to F# and I'm playing around with FParsec. I would use FParsec to generate an AST. I would like to use FsUnit to write some tests around the various parts of the parser to ensure correct operation. I'm having a bit of trouble with the syntax (sorry, the exact code is at work, I can post a specific example later) so how exactly could one compare two discriminated unions (one the expected, the other the actual result)? Could someone provide a tiny code example using FsUnit (or NUnit), please? An example discriminated union (very simple) type AST = | Variable of string | Class of

Visual Studio FsUnit test setup - Exception NUnit.Engine.NUnitEngineException

↘锁芯ラ 提交于 2019-12-04 01:54:32
问题 I am using Visual Studio 2013, installed FsUnit 2.2.0, which requires NUnit 3.2.1 and FSharpCore 3.1. I created a separate test project and put a testfixture and test in there. My platform is x64 Win 10. The config is for 'AnyCPU' and 'Debug'. I've tried test settings for x86 and x64. When trying to build and create tests, I get: ------ Discover test started ------ NUnit Adapter 3.2.0.0: Test discovery starting Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in