Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a fluent assertion API for MSTest?

I've recently been exposed to the fluent interface in nUnit and I love it; however, I am using msTest.

Does anyone know if there is a fluent interface that is either testing framework agnostic or for msTest?

like image 685
JoshBerke Avatar asked Nov 19 '08 15:11

JoshBerke


People also ask

Is Fluent Assertions open source?

One such library is Fluent Assertions. It is an open source library that integrates with several Microsoft platforms such as . NET or . NET Core, and supports several testing frameworks including MS Test, NUnit and XUnit.

Should I use fluent Assertions?

Fluent Assertions are important in unit testing because they allow the code to be easily read and followed. This makes it easier to determine whether or not an assertion is being met. As a result, everyone can easier read and understand unit tests, making it easier to locate the failing assert.

What is fluent Assertions C#?

Fluent Assertions is a set of . NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit test.

What is assertion scope?

Assertion Scopes make our lives easier when using multiple assertions within our unit tests by saving us time and effort when finding out why our tests are failing. Assertion Scopes allow us to test multiple assertions within a single test execution.


1 Answers

See Fluent Assertions. You can do stuff like

"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
like image 89
Dennis Doomen Avatar answered Sep 20 '22 14:09

Dennis Doomen