Skip to main content

One post tagged with "unit test"

View All Tags

Unit Testing - Test Spy Pattern

· 5 min read
Kyle Oettle
Software Engineer

Hi Everyone 👋

90% of blogs I read start with something about unit testing, so to not dissapoint anyone I'm making my first blog post about unit testing 😄

I'm a fan of unit testing code for various reasons, mostly because I've felt the pain when there were none! So I want to chat about a pattern I've been using for the better part of a decade but only found out today that it's called the Test Spy Pattern.

The Test Spy is designed to act as an observation point by recording the method calls made to it by the SUT as it is exercised. During the result verification phase, the test compares the actual values passed to the Test Spy by the SUT with the values expected by the test.

Okay I don't think my implemntation is exactly the classic Test Spy pattern, but close enough!