Automated Testing using bitcoind in regtest mode, problems due to race condition
I would separate out the unit tests and the integration tests.

If the function needs to go out to the internet or wait for the blockchain, I make them integration tests which I can run less frequently like every five minutes. The functions that are fast I like to run every 10 seconds.

Linking the errors to sensible time stamped logs like pm2 and key-metrics allows you to see what has been going on while you were sleeping.