There is a widely established model for writing unit tests called “Arrange, Act, Assert,” and it keeps your tests short and clean.
Essentially what you’re doing is breaking up your test into those three parts. It makes it easier for you to write, and easier for other devs running your tests (or using them as code samples for their own work) to follow. I take the time to decorate every one of my tests with these sections. Most devs don’t, but I think it’s worth the effort and provides cleanliness rather than clutter.
Here’s what that looks like:
private int MultiplyTwoNumbers(int first, int second) { return first * second; } [TestMethod] public void MultiplyTwoNumbers_TwoIntegers_ResultIsCorrect() { // Arrange int a = 5; int b = 6; int expectedResult = 30; // 5 x 6 = 30 // Act int actualResult = MultiplyTwoNumbers(a, b); // Assert Assert.AreEqual(expectedResult, actualResult, "The numbers were not multiplied correctly"); }
You see how the insertion of the section header comments makes it easy to follow? A dev who ran the test but was unsure of what exactly was being tested could start at the very bottom, where the Assert (the check) happens. A dev who wanted to see how to call your Multiply method could start at the “Act” line for a concrete code example.
This also encourages you to keep your tests short and focused. Get in and get out.
Using the “Arrange, Act, Assert” approach is widely understood as a best practice; there’s no real downside, other than having to type a bit more.

