In this article, we will learn about AAA Pattern in the Unit Test case. If you are new to this series, I will recommend you to go through the below articles of this series.
Arrange-Act-Assert (3A Pattern) is simple and provides a uniform structure for all the tests in the suite.
Arrange
Arrange is the section where you set up the objects which need to be tested. In this stage, you bring the system under the test by either directly creating or mocking the object.
Act
In the Act section, we act upon the system under the test. The act should cover the main things (method or dependencies) which have to be tested.
Assert
Assert section is used to verify the result. It verifies that the action of the method under the test behaves as expected. In the below image, you can clearly see the Arrange-Act-Assert pattern which we have written in the previous article.

In the above example, I used Assert.AreEqual() helper method to determine whether the method under the test is performing correctly or not. Assertions are central to the unit testing whichever Unit testing framework you choose. Asserts are the fundamental building block for the unit test cases. NUnit provides a rich set of assertions as the Static Method of the Assert class. NUnit supports both Classic Assert as well as a constraint-style assertion. Let’s understand some of the popular methods (most of the methods have multiple overload versions, I am only sharing only one of each for the understanding purpose).
Classic Asserts
1. AreEqual
Assert.AreEqual() is one of the most often used asserts. This method has several overload versions which can be used as per the requirement.
public static void AreEqual(object? expected, object? actual)
2. Less/Greater
Assert.Less() and Assert.Greater are two helper methods that are used to compare the expected and actual value.
public static void Greater(int arg1, int arg2);
public static void Less(int arg1, int arg2);
3. GreaterOrEqual/LessOrEqual
Used to assert that arg1>=arg2 for checking the GreaterOrEqual condition and arg1<=arg2 to check the LessOrEqual condition.
public static void GreaterOrEqual(int arg1, int arg2);
public static void LessOrEqual(int arg1, int arg2);
4. IsNull/isNotNull
Assert.isNull() is used to check the given object is null and Assert.IsNotNull() is used to check that given object is not null.






Join the conversation! Your thoughts help the community grow.