MSTest用の流れるようなアサーションAPIはありますか?
-
08-07-2019 - |
質問
最近、nUnitの流れるようなインターフェイスに触れましたが、とても気に入っています。ただし、msTestを使用しています。
フレームワークにとらわれないテスト用またはmsTest用の流なインターフェイスがあるかどうか、誰もが知っていますか?
解決
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
他のヒント
http://sharptestex.codeplex.com/
を参照してください。注:SharpTestsExはもはや積極的に開発されていないようです。推奨される代替手段は http://www.fluentassertions.com/です。 。
SharpTestsEx(Sharp Tests Extensions)は、拡張可能な拡張機能のセットです。主な目標は、Visual Studio IDEインテリセンスがガイドとなる短いアサーションを書くことです。 #TestsExは、SilverlightでもNUnit、MsTests、xUnit、MbUnitで使用できます。
強く型付けされたアサーションの構文例(Webページから取得):
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();
私の研究によると、それはありませんが、アサートが失敗し、新しいdllを追加する理由に関してより良い報告可能性を犠牲にしたい場合は、nunitを参照してそれらを使用できます。...
所属していません StackOverflow