O'Reilly logo

Testing with F# by Mikael Lundin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arrange, act, assert

To bring order into our unit tests, there are certain patterns to follow. One of the most common and popular patterns is the triple A (AAA) syntax, where the A's stand for:

  • Arrange
  • Act
  • Assert

The best way to visualize this is in code. Let's see how it works in C# code and then move on to the F# equivalent:

using NUnit.Framework; using SUT = Company.System.BL.Calculators; namespace Company.System.Tests.BL.Calculators.PriceCalculator { public class GetPrice { [Test] public void ShouldReturnZeroOnEmptyOrder() { // Arrange var priceCalculator = new SUT.PriceCalculator(); var order = new { }; // Act var result = priceCalculator.GetPrice(order); // Assert Assert.That(result, Is.EqualTo(0), "Expecting zero price when order is empty"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required