c# - 如何在 C# 中引用 UnitTesting DataSource 中的对象定义?
问题描述
我正在使用 Microsoft UnitTesting 套件 ( 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} }
};
我试图在我的单元测试中引用这些:
[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));
}
但是,运行时,我收到错误消息
在测试配置设置中找不到数据源“ValidLogRangesIntSource”。
调查时,DataSource 的文档告知名称应该在app.config
; 但是我没有这个文件。
此外,在 NUnit 中,数据源运行良好[TestCaseSource("ValidLogRangesIntSource")]
- 我正在寻找相同的实现。
解决方案
推荐阅读
- java - 我们可以使用 springboot 对 nodejs 应用程序进行身份验证吗?
- asp.net - 如何在 Open ID Authentication 中在主应用程序和虚拟应用程序之间共享授权?
- javascript - 在解决以下问题时面临问题
- java - java Selenium如何验证文本的值
- react-native - 如何在没有证书的情况下设置远程通知?(注册护士)
- c# - 具有动态 IP 地址的服务器客户端
- c# - WPF 如何将 ComboBoxes 选定项用作 xctk:PropertyGrid 在 MVVM 中的 SelectedObject
- javascript - 在桌面和移动设备之间重新排列 div
- amazon-web-services - 允许/限制 AWS 安全组中的应用程序协议,如 ampq、mongodb、HTTP 等
- python - PicklingError: 不能腌制
: 属性查找 __builtin__.function 失败(多处理)