3

I'm trying to figure out how to set up and use FsCheck by going through the following blog post:

http://www.clear-lines.com/blog/post/FsCheck-2b-XUnit-3d-The-Bomb.aspx

I've tried my best to mimic the whole process in the post, and everything works fine until the following piece of code:

namespace FSharpTests

open Xunit
open FsCheck
open FsCheck.Xunit
open CSharpCode

module Specification =

[<Property>]
let ``square should be positive`` (x:float) =
x * x > 0.

According to the image in the blog post, this should result in one failed test in the Test Explorer. In my case however, I get this:

Nothing

I've tried messing around a bit with the code, and it seems that the [<Property>] attribute is the culprit.

The following piece of code, which contains some of the previous code from the blog post, will run fine if said attribute is outcommented, producing two passing tests, but produce nothing (see above image) otherwise.

namespace FSharpTests

open Xunit
open FsCheck
open FsCheck.Xunit
open CSharpCode

module Specification =

    [<Fact>]
    let ``length above 8 should be valid`` () =
        let password = "12345678"
        let validator = Validator ()
        Assert.True(validator.IsValid(password))

    [<Fact>]
    let ``length under 8 should not be valid`` () =
        let password = "1234567"
        let validator = Validator ()
        Assert.False(validator.IsValid(password))

    //[<Property>]
    let ``square should be positive`` (x:float) =
        x * x > 0.

Am I doing something wrong? Is something missing?

I am currently running...

  • Visual Studio Ultimate 2012 Version 11.0.61030.00 Update 4
  • F# 3.0 (I guess..? How do I check this exactly?)
  • FsCheck 0.9.4.0
  • FsCheck.Xunit 0.4.1.0
  • xUnit.net 1.9.2
  • xUnit.net runner for Visual Studio 0.99.7

Update

I tried the example on another computer, with the same results. However, I noticed a warning in the error list, which I didn't notice was also there on the laptop which I first tried this on.

The description says:

Found conflicts between different versions of the same dependent assembly.

Navigating to the source of the warning, opens up Microsoft.Common.targets in an editor, showing me thousands of lines of incomprehensible XML and 101 further warnings.

If i remove the FsCheck packages and close the Microsoft.Common.targets file, all warnings disappear. I'm guessing this warning might be a clue to why things aren't working as expected, I'm still clueless how to solve this, though.

Patrick McDonald
  • 64,141
  • 14
  • 108
  • 120
phaz
  • 872
  • 9
  • 23
  • 1
    Have you installed the [xunit runner package into Visual Studio](http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099)? [Everything else is fine](http://stackoverflow.com/questions/16214684/why-is-the-xunit-runner-not-finding-my-tests) – Ruben Bartelink Jul 08 '14 at 22:07
  • Yup. The runner is installed. :-) – phaz Jul 09 '14 at 09:00
  • 1
    Ah, didnt read the Q very well - you had ruled out those possibilities pretty well so it's down to a crash/hang during discovery. What does the output window (selecting tests in the dropdown) show? How about attaching a debugger to the `vstest.discovery`* process and trapping on exceptions? – Ruben Bartelink Jul 09 '14 at 09:55
  • 1
    Which version of Visual Studio, F#, FsCheck and FsCheck.Xunit are you using? I have tried using that exact code with the latest xunit runner and FsCheck packages in VS2013 and it worked. – Kurt Schelfthout Jul 09 '14 at 12:25
  • 1
    (Addendum to Kurt's point) Perhaps there are missing binding redirects (in app.config) resulting from inconsistencies in play ? (`Add-BindingRedirect` in Package Manager Console window). (And it prob doesnt apply in this case but any such app.config changes may not be picked up without a restart) – Ruben Bartelink Jul 09 '14 at 16:00
  • Hi guys. Thanks for the comments. I've update my post with more information. Please take a look. :-) – phaz Jul 09 '14 at 21:00
  • @KurtSchelfthout I've now installed VS2013 and tried it there as well, where it works flawlessly. So it seems the problem is constrained to VS2012. :-S – phaz Jul 09 '14 at 21:55
  • 1
    Yes, that makes sense. FsCheck is built with F#3.1, VS2012 afaik uses F#3.0. You can try modifying the BindingRedirects in the app.config file to redirect to 4.3.0.0 instead, maybe NuGet will do the right thing as @RubenBartelink suggests, but I'm not sure. – Kurt Schelfthout Jul 11 '14 at 07:54
  • It already has however, changing it to and restarting VS2012, seems to make things work. The warning is still there, however. Should I worry about this? – phaz Jul 11 '14 at 22:10
  • I found a different approach that also seems to work fine. I've removed the current FsCheck and FsCheck.Xunit packages, and then added FsCheck 0.9.3, which is the last version before they switched to F# 3.1, follow by FsCheck.Xunit. Now there's no warnings and the tests show up fine. According to their release notes, the only thing I'll be missing out on at the moment is "Hardened other generators against the new null-generating string generator.". I'm kinda curious as to why they suddenly chose to switch to F# 3.1. :-S – phaz Jul 11 '14 at 22:29
  • 1
    I switch to latest F# compiler versions and FSharp.Core versions as a matter of course. This is not a question of choosing the lowest version that works; every version is just as incompatible (for the build & loading system) with every other. E.g. if FsCheck would be on F# 3.0, people that wanted to use F# 3.1 would have the exact same problem as you. – Kurt Schelfthout Sep 04 '14 at 09:53
  • Huh... I can't remember, is FsCheck open source, and if so, would one be able to obtain and compile the source in e.g. F# 3.0, (given that it doesn't use version specific features of course)? – phaz Sep 04 '14 at 15:41

1 Answers1

1

It appears that test discovery fails silently if binding redirects are not set properly. This just cost me about 3 hours, so I feel the pain. Just add an App.config file to your test project with appropriate redirects. I had to redirect FSharp.Core too like so: https://github.com/fscheck/FsCheck/issues/151

Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70