Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.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/unit-testing/4.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#中引用UnitTesting数据源中的对象定义?_C#_Unit Testing_Mstest - Fatal编程技术网

如何在C#中引用UnitTesting数据源中的对象定义?

如何在C#中引用UnitTesting数据源中的对象定义?,c#,unit-testing,mstest,C#,Unit Testing,Mstest,我正在使用Microsoft单元测试套件(Microsoft.VisualStudio.TestTools.UnitTesting;)编写单元测试。通过此操作,我创建了一个用作数据源的对象: private static readonly object[] ValidLogRangesIntSource = { new object[] { 1, 2, 1, new List<int> {1} } , new object[] { int.MaxValue, 1, 1

我正在使用Microsoft单元测试套件(
Microsoft.VisualStudio.TestTools.UnitTesting;
)编写单元测试。通过此操作,我创建了一个用作数据源的对象:

private static readonly object[] ValidLogRangesIntSource =
{
    new object[] { 1, 2, 1, new List<int> {1} } ,
    new object[] { int.MaxValue, 1, 1, new List<int> {int.MaxValue} } ,
    new object[] { int.MaxValue, 1, 2, new List<int> {int.MaxValue, 1} } ,
    new object[] { 1, 1000, 10,
        new List<int> { 1, 2, 5, 10, 22, 46, 100, 215, 464, 1000} },
    new object[] { 1000, 1, 10,
        new List<int> { 1, 2, 5, 10, 22, 46, 100, 215, 464, 1000} }
};
私有静态只读对象[]ValidLogRangesIntSource=
{
新对象[]{1,2,1,新列表{1},
新对象[]{int.MaxValue,1,1,新列表{int.MaxValue},
新对象[]{int.MaxValue,1,2,新列表{int.MaxValue,1},
新对象[]{1,1000,10,
新名单{1,2,5,10,22,46,100,215,464,1000},
新对象[]{1000,1,10,,
新名单{1,2,5,10,22,46,100,215,464,1000}
};
我试着在单元测试中提到这些:

[TestMethod]
[DataSource("ValidLogRangesIntSource")]
public void TestLogRangeWithValidIntValues(int start, int end, int steps, List<int> result)
{
    // MathUtil.LogRange(start, end, steps).Should().BeEquivalentTo(result);
    CollectionAssert.AreEquivalent(result, MathUtil.LogRange(start, end, steps));
}
[TestMethod]
[数据源(“ValidLogRangesIntSource”)]
public void testlograngewithvalidintvalue(int start、int end、int steps、List result)
{
//LogRange(开始、结束、步骤).Should().beequivalento(结果);
AreEquivalent(结果、MathUtil.LogRange(开始、结束、步骤));
}
但是,当运行时,我会收到错误消息

在测试配置设置中找不到数据源“ValidLogRangesIntSource”

调查时,通知名称应位于
app.config
;但是我没有这个文件

此外,在NUnit中,数据源与
[TestCaseSource(“ValidLogRangesIntSource”)]
配合得很好-我正在寻找相同的实现