How to test my installation script on macOS?

Your best bet is to create a macOS VM for testing. Install VirtualBox (it's free), create a macOS virtual machine, and then create a snapshot before testing your script. Once you've finished testing your script you can restore the VM to its previous, unmodified state using the snapshot feature. Hope this helps!