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.

4

1 回答 1

1

如果绑定重定向设置不正确,测试发现似乎会静默失败。这只花了我大约3个小时,所以我感到很痛苦。只需App.config使用适当的重定向将文件添加到您的测试项目。我也不得不像这样重定向 FSharp.Core:https ://github.com/fscheck/FsCheck/issues/151

于 2015-09-15T22:24:02.453 回答