Readable

This characteristic of unit tests can not be overemphasized. Similar to the code under test, unit tests should be easy to read and understand. The coding standards and principles are also applicable to tests. Anti-patterns, such as magic numbers or constants, should be avoided as they can clutter tests and make them difficult to read. Integer 10 in the following test is a magic number, as it was directly used. This affects the test readability and clearity:

[Fact] public void Test_CheckPasswordLength_ShouldReturnTrue() {      string password = "civic";        bool isValid=false;    if(password.Length >=10)        isValid=true;        Assert.True(isValid); }

There is a good test structuring pattern that can be adopted, it's widely known as the triple A or ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.