Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Xunit使用F#执行测试列表_C#_.net_Testing_F#_Xunit - Fatal编程技术网

C# 使用Xunit使用F#执行测试列表

C# 使用Xunit使用F#执行测试列表,c#,.net,testing,f#,xunit,C#,.net,Testing,F#,Xunit,我正在F#中使用Xunit,使用VisualStudio作为IDE执行多个具有相同形式的测试。例如,这里有一个可能执行的一些测试的示例 let add x y = x + y //Now we want to test this [<Fact>] let test1() = Assert.True(add 0 1 = 1 , "userMessage") [<Fact>] let test2() = Assert.True(add 1 1 = 2 ,

我正在F#中使用Xunit,使用VisualStudio作为IDE执行多个具有相同形式的测试。例如,这里有一个可能执行的一些测试的示例

let add x y = x + y
//Now we want to test this
[<Fact>]
let test1() = 
    Assert.True(add 0 1 = 1 , "userMessage")

[<Fact>]
let test2() = 
    Assert.True(add 1 1 = 2 , "userMessage")

[<Fact>]
let test1() = 
    Assert.True(add 1 2 = 3 , "userMessage")
让我们加上xy=x+y
//现在我们要测试这个
[]
设test1()
Assert.True(添加0 1=1,“userMessage”)
[]
设test2()
True(添加1=2,“userMessage”)
[]
设test1()
Assert.True(添加12=3,“userMessage”)
也许还有更多

这有点重复,所以我决定写以下内容

let listOfTests = 
    [
       0  ,  1  ,  1  ,  "userMessage"
       1  ,  1  ,  5  ,  "userMessage" //this should fail
       1  ,  2  ,  6  ,  "userMessage" //this should also fail
    ] 

 let testMaker (in1 , in2 , out , mess)
     let truth = add in1 in2 = out
     Assert.true(truth , mess)

[<Fact>] //I think that this might be where I need to make changes?? 
let runTests()=
    List.map testMaker listOfTests
    |>ignore
让listOfTests=
[
0、1、1,“用户消息”
1,1,5,“userMessage”//这应该失败
1、2、6,“用户消息”//这也应该失败
] 
让testMaker(输入、输入、输出、混乱)
让真理=加进去2=出
断言。正确(真实、混乱)
[]//我认为这可能是我需要进行更改的地方??
让我们运行测试()=
List.map测试生成器listOfTests
|>忽略
这类测试的工作方式是执行测试,但当我运行runtests()时,只有第一个失败的测试显示在我的测试资源管理器中,而不是应该失败的第二个测试。我看过一些关于理论的代码,但代码大部分是用C#编写的,我在翻译方面遇到了一些问题。我试着用, [] []


作为属性,而不是简单地去“类型理论是没有定义的”。对于PropertyData也是如此。

如您所述,您应该使用
[]
属性。您使用的是XUnit1还是XUnit2?在xUnit 1中,
TheoryAttribute
类型位于名为
xUnit.extensions
的单独程序集中,同样位于命名空间
xUnit.extensions
中。在xUnit 2中,它应该位于
xUnit
名称空间中,无需执行任何特殊操作。此外,您看到的行为是正确的-使用一个
[]
属性,您正在运行一个测试,并且只要其中的任何内容抛出异常(如失败的断言所做的),就不会执行任何其他操作,只报告了一次失败。@TeaDrivenDev谢谢您的评论。我没有意识到它们是在一个单独的集合中。这对xUnit 1来说有点恼火,因为理论非常常用;由于这个原因,他们被转移到XUnit2的核心项目。如果您可以切换到XUnit2,您可能应该这样做。