How to solve Command CodeSign failed with a nonzero exit code error

I was building a macOS app and wanted to rename the XCode project. I carefully changed the project name, folder and filenames and updated the settings. Then I did a clean build and run the app. Everything worked like a charm.

However when I tried to run unit tests I faced a “Command CodeSign failed with nonzero exit code.” error. It was a very tricky problem to solve, since eventually I found out that it had not anything to do with my project settings.

How did I managed to solve it then? I opened the Keychain Access app and locked the login key chain. Then I opened up the key chain using my login password. I did a clean build in XCode and then I could run the unit tests without the CodeSign error.