Approval Testing

Approval Testing is one of my newest discoveries. It is amazingly helpful and I wonder why it’s not more known and used.

Image that you have a complex functionality which you want to test. For example a complex report or the rendering of a picture. Here regular unit testing just doesn’t help you that much. Mainly because you are just unable to formulate a reasonable accept condition. How do you check that your code rendered the right picture?

Here is where approval testing comes in. The basic concept is that we are good at recognizing if something looks correct or not. So instead of writing any condition we do approvals. First we write our scenario. Then the code runs and produces are result. Now instead of doing complex checks we either approve or disapprove the output. Once we approved the result it will ensure that the result doesn’t change. The approval test will catch any changes in the output. If it does, it will prompt us to either approve the changes or we can fix the issue. The nice thing about this is that with a diff tool you easily can spot what has changed and if the changes are correct.

Instead of posting an example here myself I just refer to the official website. The concept is explained in a short step by step example.

Approval Testing in Portal 2

Approval Testing in Portal 2

Where is approval testing useful? I think that there are a lot of places where it is useful. Certainly it can be used for integration tests. There you can test complex outputs and approve / disapprove changes in behavior. In general complex, like pictures, is a great place for approval testing. I myself used it test chart- rendering. Another big area is legacy code, where you first want to setup a test framework to prevent regressions.

Listen to this podcast where everything is explained in much more detail. Finally here is an approval testing libraries for Java, C#, Ruby and PHP which works with most testing frameworks.

My last words: Approval Testing is AWESOME and should be in your tool belt. There will arise a situation where it makes you life so much easier. And if you haven’t played Portal 2, here’s a video of acceptance testing in action 😉