c# - CollectionAssert.Contains() 作为 NUnit 的 Assert.Contains() 的替代品

标签 c# testing nunit

我在我的 Visual Studio 项目中用 TestManager 替换了 NUnit。 NUnit 具有以下断言:

  • Assert.Contains(string, collection)
  • Assert.That(collection, Has.No.Member(string))

我正在为 TestManager 使用以下内容:

  • CollectionAssert.Contains(collection, string)
  • CollectionAssert.DoesNotContain(collection, string)

我正在寻找一种替代方法

Assert.IsEmpty(collection)Assert.IsNotEmpty(collection)

我可以使用 CollectionAssert.DoesNotContain(collection, new List<string>())但宁愿有一些更扎实的东西反射(reflect)在收藏上。

最佳答案

LINQ 通常适用于检查集合。

 Assert.IsFalse(collection.Any()); //      Assert.IsEmpty(collection) 
 Assert.IsTrue(collection.Any()); //      Assert.IsNotEmpty(collection) 

如果您正在寻找更流畅的界面 - 请考虑 FluentAssertions NuGet .

collection.Should().BeEmpty("because there are no doors");

关于c# - CollectionAssert.Contains() 作为 NUnit 的 Assert.Contains() 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402307/

相关文章:

c# - Fluent Security - 配置参数化 Controller 操作

python - 使用 testbook 测试 Jupyter notebook 单元时如何修补 input()?

php - 测试未链接到任何路由的 Controller 方法

c# - .NET Core 2.1 DbContext ObjectDisposedException 依赖注入(inject)

c# - 无法从标记为异步的方法返回 IObservable<T>

c# - 为 asp.net 实现测试自动化

visual-studio-2008 - nunit 不是 vs2008 中可用的测试框架

c# - 单元测试未涵盖 LINQ `Any`

c# - XML序列化和生成HTML文档时的 "<"、 ">"

testing - Window defender 想要重置您的设置”-ChromeDriver 2.29 问题 :ChromeBrowser opening with a new tab