Recently I have been testing signing executable installers and needed a self-signed certificate for testing purposes. Below I outline a very simple way to go about this after trying several different methods.
Generating a self-signed certificate for code signing
Execute the following from an elevated PowerShell prompt.
In my case I installed Windows App Certification Kit x64-x86_en-us.msi, which installs the executable to C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe
Deleting these self-signed certificates
To cleanup after testing, you probably want to delete these from your certificate store. Open up the certificate store (search Win+S for certificates and open up Manage Computer Certificates).
Under Personal\Certificates\ and Intermediate Certification Authorities\Certificates\ delete the certificates you installed earlier, they will have as their issue name the -DnsName you assigned them earlier.