Note
The examples shown here are generated from the source code. They therefore represent the behavior of the application at any times. Non regression is ensured by checking the absence of change in this document. Learn more here https://github.com/sfauvel/documentationtesting

View source of project on Github

Demo test

Demo of a property base testing generating a documentation.

We generate a list of objects with some random values. We group objects by the invariant, the value to check or by the result of a property. When there is only one value, we can display it and approved the document (like in chapter below). When there is more than one value, we write them so the test fail, and we have all information to investigate.

Should ignore taxes if type is TAX FREE

With TAX_FREE, tax is always 0

This property has been verified using 10 products.

Code description

We show here the code used to create the above chapter.

final TaxType taxType = TaxType.TAX_FREE;
List<Product> products = ProductGenerator.generate(Product::setTaxType, taxType);

final Map<Integer, List<Product>> productsByTax = products.stream()
        .collect(Collectors.groupingBy(Product::getTaxes));

write(String.format("With %s, ", taxType.name()));
if (productsByTax.size() == 1) {
    write(String.format("tax is always %s",
            productsByTax.keySet().toArray()[0]),
            "", "");
} else {
    write("tax is not always the same values",
            valuesToString(productsByTax),
            "", "");
}

write(String.format("This property has been verified using %s products.", products.size()));