I am scared of unit testing. There, I’ve said it. Unit testing is one of those practices that I know I should be doing, there are benefits to doing it, but it just seems too hard to implement, especially with an established codebase. Recently I have been building our next plugin and throughout its development I have had a nagging voice in my head constantly reminding me about unit tests. So I’ve taken the plunge and started writing tests. In this post I will introduce you to unit testing a WordPress plugin, using my recent experience as a guide. What is Unit Testing Let’s get this out the way early: unit testing is the practice of testing the smallest units of code, usually functions and methods, to make sure they are working correctly. Typically this means passing in data to a method for a specific scenario and ensuring the result or return data is as expected. Unit testing is actually quite simple, which was one of my main misconceptions that originally put me off doing it. Take WP Offload S3 as an example. The plugin uploads files to Amazon S3. Right, so how far should I test? When testing the upload method, should the test actually check if the file exists on S3 after the upload
Share This