Earlier this month, we began looking at installing PHPUnit in Visual Studio Code with the ultimate goal of learning how to write unit tests for our WordPress-based projects.

To that end, this post assumes that you’ve read the following posts and it assumes that you’ve caught up with a handful of previous posts:

  1. A WordPress Development Environment (Using a Package Manager)
  2. An IDE for WordPress Development
  3. Working with User Settings in Visual Studio Code

And, of course, installing PHPUnit in Visual Studio Code as linked above. Once that’s done, we’ll be ready to proceed. But one thing to keep in mind is that this will night be a traditional or a comprehensive course in writing unit tests.

Intalling PHPUnit in Visual Studio Code: Installing the PHPUnit Extension

Instead, it’s all about writing unit tests for WordPress projects.

Unit Tests with PHPUnit, Part 1: The Set Up

Before getting too deep into this, I want to be clear that this isn’t so much a post in test-driven development but a post that lays the foundation for understanding writing unit tests. And then, ultimately, we’ll work towards writing unit tests for our code.

Writing Unit Tests with PHPUnit

For those of you who have done any prior reading on unit testing then you know writing unit tests is a topic for which there is a lot of information and this post isn’t going to attempt to cover all of that. Instead, it’s going to take a more pragmatic approach to writing unit tests against WordPress-based plugins, web applications, and the like.

For Members Only

Thanks for your interest in this article; however, it's available to members only. If you'd like to review this (and have access to all previous and future articles), check out the sign-up page.

Ultimately, we’re working towards getting a full picture of how to do this and how to do it right. But it’s important to lay the foundation for that and doing so over the span of a few posts is easier than in one monolithic post.

So examining tearDown(), it’s use, and how to execute tests from the command-line will be the topic of the next post in this series.

Category:
Articles
Tags:
,