Pure Unit Tests

Pure unit tests are simple unit test cases in which “pure” functions are tested.

Pure functions are those that:

  • Do not contain any “side effects”
  • Map the same input to the same output no matter how many times they are invoked.

Here’s an example of a simple test of a tax calculator function:

using FluentAssertions;
using Xunit;
using static NeverendingTeaShop.Application.TeaPriceCalculator;

namespace NeverendingTeaShop.Application.Tests
{
    public class TeaPriceCalculatorTest
    {
        [Fact]
        public void CalculateTaxedPrice_GivenARetailPrice_ReturnsFullPriceWithTaxApplied()
        {
            CalculateTaxedPrice(19.99).Should().Be(21.74);
        }
    }
}

Frameworks in use to run this test are: