Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrange Act Assert Alternatives

The general question is are there alternative patterns to AAA for unit testing? If, yes, would be very interesting to see some examples and hear about their pros and cons.

And as the simplest example of AAA test (in c#, using var for the sake of simplicity):

// Arranging
var annualSalary = 120000M;
var period = 3; // for a quarter profit
var calc = new SalaryCalculator();

// Acting
var result = calc.CalculateProfit(annualSalary, period); 

// Assertion
Assert.IsEqual(40000, result);
like image 777
Arman Avatar asked Dec 21 '12 12:12

Arman


People also ask

What is the AAA pattern?

The AAA pattern is a common unit testing pattern. It is a way to arrange and organize test code to make unit tests clear and understandable, and consists of separating each unit test method into three sections: Arrange, Act, and Assert.

What are the three A's of unit testing?

The idea is to develop a unit test by following these 3 simple steps: Arrange – setup the testing objects and prepare the prerequisites for your test. Act – perform the actual work of the test. Assert – verify the result.

What is AAA principle?

Authentication, authorization, and accounting (AAA) is a term for a framework for intelligently controlling access to computer resources, enforcing policies, auditing usage, and providing the information necessary to bill for services.

What is AAA testing?

Abdominal aortic aneurysm (AAA) screening is a way of checking if there's a bulge or swelling in the aorta, the main blood vessel that runs from your heart down through your tummy.


2 Answers

I like something that is not so much an alternative to AAA, but rather a variation. I think of it as Arrange-Assert(not)-Act-Assert, but others have called it a Guard Assertion. The idea is to have an assertion that ensures the desired result of the Act is not already present before the act. There's a good discussion of it here.

like image 138
Carl Manaster Avatar answered Sep 22 '22 13:09

Carl Manaster


There is another notation from Behavior-driven development: Given - When - Then. Examples for c# is SpecFlow and for Jasmin for JavaScript. Both resource are full of examples of using this notation. The GWT approach is typically used in a Behavior Driven Development and Aspect Oriented Programming.

like image 20
Akim Avatar answered Sep 25 '22 13:09

Akim