I am looking for a solid way to keep track of the number of assertions made in a unit test for reporting purposes in automation. I know that with Nunit one is able to keep track of the assertions that are being made for a test with TestContext.CurrentContext.AssertCount
. The problem is that my team has our own set of assertion methods using fluent assertions and am looking to find a way to increment that value anytime one is made. Below is a stripped version of one of our unit tests so that you can get an idea of how they read.
[Test]
public void ServiceHistoryButton_Asset(Dictionary<string, string> data)
{
Threaded<Session>.CurrentBlock<HomePage>()
...
.VerifyThat(form => form.Containerservice.Should().Contain(data["Containerservice"]))
.VerifyThat(form => form.Account.IsDisplayed().Should().BeTrue())
.VerifyThat(form => form.ContainerGroup.IsDisplayed().Should().BeTrue())
.StoreValue<AssetServiceHistoryEdit, DateTime>(form => form.Service.First().ServiceDate, out DateTime firstDate)
.VerifyThat(form => form.Service.ElementAt(2).ServiceDate.Should().BeBefore(firstDate))
}
I looked into the NUnit framework a bit and if I'm seeing it correctly it looks like they are extending the Assert.That method and adding an incrementer to keep track of when it is called. I thought about doing something similar, but it doesn't look like I can access the TestContext
outside of the test itself, nor the setup or teardown methods. Let me know if I'm not explaining myself clearly or if I can provide anymore info. Thanks.