Ashutosh Wahane's solution worked for me, but I think I may have found the culprit of the problem. I'll explain my observations.
In Wahane's solution he add 'task("testClasses")' to the build script. He mentioned that he added it to the Kotlin block of the build script. I added it outside the Kotlin block and his solution still worked. What I noticed was after doing a successful build with that extra line added to the build script, I could then delete that line of code from the build script and things still worked until I did a "clean". At which case I would have to add the line of code again, do a build, and then I once again could go back and delete that extra line of code. If you leave that extra line of code in the build script, it appears that Wahane's solution is a good work around. What I'm not sure is whether that breaks your kmm's shared tests!
With all that said, I started more carefully looking at the build errors I was getting when the error occurs. What I noticed was that I was getting a lot of errors related to the Gradle build configuration cache. I looked at my "gradle.properties" file and saw that it contained the line:
org.gradle.configuration-cache=true
I set that value to false, and I no longer got the "testClasses" not found error without that extra line added to the build script. From seeing this result, it seems to suggest that the error is a Gradle bug related to using the configuration cache.
If you have problems running tests for the shared kmm code after applying Wahane's solution, then this might be a better workaround solution for you until the configuration cache problem gets fixed in the gradle plugin.