Testing WordPress plugins on a live site can go very wrong! I have discovered a simple way to test WordPress plugins locally: wp-env. This CLI tool makes it really easy to create an instance of a docker container which runs the latest verson of WordPress.
To add wp-env as a local developer dependency:
npmi@wordpress/env--save-dev
Set-up
I recommend creating a config file for wp-env. If you have a repo where you are developing a plugin, then use something like the following in your .wp-env.json file. This example tells wp-env that you are working on two plugins, and lists the directories which contain the plugin files:
The command to start up the WordPress containers is:
npxwp-envstart
Once the containers are up and running, you should be able to access the WordPress site at localhost:8888. The default username and password are admin and password! The plugins should be pre-installed and ready for testing.