14
A
回答
17
见Fluent Assertions。你可以做类似于
"ABCDEFGHI".Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);
new[] { 1, 2, 3 }.Should().HaveCount(4, "because we thought we put three items in the
collection"))
dtoCollection.Should().Contain(dto => dto.Id != null);
collection.Should().HaveCount(c => c >= 3);
dto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer);
dt1.Should().BeWithin(TimeSpan.FromHours(50)).Before(dt2);
Action action =() => recipe.AddIngredient("Milk", 100, Unit.Spoon);
action
.ShouldThrow<RuleViolationException>()
.WithMessage("Cannot change the unit of an existing ingredient")
.And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity
0
根据我的研究没有一个,但如果你愿意去尽可能为什么断言失败的牺牲更好的可报告,并愿意加你可以参考NUnit的,并使用他们的一个新的DLL ....
5
请参阅http://sharptestex.codeplex.com/
注:SharpTestsEx似乎不再积极开发,推荐的替代方案是http://www.fluentassertions.com/。
SharpTestsEx(夏普测试扩展)是一组可扩展的扩展。主要目标是编写Visual Studio IDE intellisense是您的指南的简短断言。 #TestsEx可以与NUnit,MsTests,xUnit,MbUnit ...甚至在Silverlight中一起使用。
语法例如强类型断言(从网页上获取):
true.Should().Be.True();
false.Should().Be.False();
const string something = "something";
something.Should().Contain("some");
something.Should().Not.Contain("also");
something.ToUpperInvariant().Should().Not.Contain("some");
something.Should()
.StartWith("so")
.And
.EndWith("ing")
.And
.Contain("meth");
something.Should()
.Not.StartWith("ing")
.And
.Not.EndWith("so")
.And
.Not.Contain("body");
var ints = new[] { 1, 2, 3 };
ints.Should().Have.SameSequenceAs(new[] { 1, 2, 3 });
ints.Should().Not.Have.SameSequenceAs(new[] { 3, 2, 1 });
ints.Should().Not.Be.Null();
ints.Should().Not.Be.Empty();
ints.Should()
.Contain(2)
.And
.Not.Contain(4);
(new int[0]).Should().Be.Empty();
相关问题
- 1. 如何用流利的断言
- 2. 如果使用流利的断言
- 3. MSTest:断言线程执行
- 4. 流利断言:断言一个或另一个值
- 5. 流利断言ShouldBeEquivalentTo总是具有不同的属性
- 6. 断言用MSTEST调用方法
- 7. MSTEST - 在断言失败后继续
- 8. 用流利的API
- 9. 用流利的API
- 10. 如何使用流利的断言报告对象的名称
- 11. 流利的断言:在一组DateTime属性上使用BeCloseTo
- 12. AssertJ - 继续用流利的断言检查
- 13. 流利的断言:比较两个数字集合大约
- 14. 流利的api和关系有问题
- 15. EF5流利的API映射
- 16. 流利的API映射
- 17. EF用流利的API
- 18. 流利的NHibernate API文档
- 19. Sitecore SearchResulItem - 流利的API?
- 20. EF Codefirst - 用流利的API
- 21. 流利的API - 一对多
- 22. 断言检查的便利策略
- 23. 流利的API与其他API有什么不同?
- 24. 代码优先:流利的api会影响UI吗?
- 25. 我不能使用.NET Portable的Code First流利API吗?
- 26. 比较集合流利的断言都应该等同于别名
- 27. Do [DataType(DataType.EmailAddress)]在流利的API中有一个计数器部分吗?
- 28. VS2012 MSTest无法捕捉断言,原生C++
- 29. 使用MSTest自定义断言 - 处理AssertFailedException
- 30. 为什么空集合断言在MSTest中不起作用?
虽然我觉得harrydev可以添加一些有用的信息,但在我看来,SharpTestEx似乎比FluentAssertions更成熟一些。当然是初步观察。任何人都可以随时向我展示为什么FluentAssertions可能会更好。 – llaughlin 2010-11-03 12:52:24
SharpTestEx基本上已经死亡,而Fluent Assertions正在积极开发并增加对所有主要单元测试框架以及所有.NET框架版本(包括.NET 4.5,WinRT,Silverlight 5和WP7/8)的支持。 – 2013-04-22 18:57:28