Assertion Methods Available in Shouldly
Get familiar with the assertion extension methods supported by Shouldly.
In this lesson, we’ll walk through a wide range of assertion extension methods supported by Shouldly. We will do so with the aid of the provided playground, which is set up with an excessive amount of assertions to demonstrate different ways of validating our test results:
namespace MainApp; public class DataManager { private readonly List<string?> _collection; public DataManager() { _collection = new List<string?>(); } public List<string?> ReadAll() { return _collection; } public void DeleteAt(int index) { _collection.RemoveAt(index); } public void DeleteAll() { _collection.Clear(); } public void Insert(string? newItem) { _collection.Add(newItem); } }
All our test methods in the above playground are in the DataManagerTestsWithShouldly.cs
file under the MainApp.Tests
folder.
Extension methods supported by Shouldly
All Shouldly extension methods can be found in the same library. As with any other assertion type, we can find an assertion method appropriate for any type of scenario.
Value assertions
These methods verify that a field, property, or variable contains an expected value.
The ShouldBe()
method
This method is used to validate what the expected value should be. We have an ...