属性抛弃xUnit和测试资源管理器

时间:2014-07-08 21:40:11

标签: testing f# xunit test-explorer fscheck

我试图通过以下博文来弄清楚如何设置和使用FsCheck:

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

我已经尽力模仿帖子中的整个过程,一切正常,直到下面的代码:

namespace FSharpTests

open Xunit
open FsCheck
open FsCheck.Xunit
open CSharpCode

module Specification =

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

根据博文中的图片,这会导致测试资源管理器中的测试失败。然而,在我的情况下,我得到了这个:

Nothing

我已经尝试过乱用代码,似乎[<Property>]属性是罪魁祸首。

下面的一段代码,其中包含博客文章中的一些以前的代码,如果所述属性被取消注释,将运行正常,产生两个通过测试,但不生成任何内容(见上图)。

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.

我做错了吗?缺少什么?

我正在运行......

  • Visual Studio Ultimate 2012版本11.0.61030.00更新4
  • F#3.0(我想......?我该怎么检查呢?)
  • FsCheck 0.9.4.0
  • FsCheck.Xunit 0.4.1.0
  • xUnit.net 1.9.2
  • 适用于Visual Studio 0.99.7的xUnit.net runner

更新

我在另一台计算机上尝试了这个例子,结果相同。 但是,我注意到错误列表中有一个警告,我没有注意到笔记本电脑上也有我第一次尝试使用它。

描述说:

Found conflicts between different versions of the same dependent assembly.

导航到警告源,在编辑器中打开Microsoft.Common.targets,向我展示数千行无法理解的XML和101个进一步的警告。

如果我删除了FsCheck软件包并关闭了Microsoft.Common.targets文件,则所有警告都会消失。我猜这个警告可能是为什么事情没有按预期工作的线索,但我仍然无法解决这个问题。

1 个答案:

答案 0 :(得分:1)

如果未正确设置绑定重定向,则测试发现似乎无声地失败。这只花了我大约3个小时,所以我感到痛苦。只需使用适当的重定向将App.config文件添加到测试项目中即可。我不得不重新定位FSharp.Core:https://github.com/fscheck/FsCheck/issues/151