Suddenly Getting Unimplemented: ContinuousClock.now On Every Test #1839
-
I've been working on a bunch of tests for my TCA-based app the last couple weeks. When I stepped away from my desk last Friday, I swear my tests were working fine. Then I sit down at my desk this morning, and everything is failing with "Unimplemented: ContinuousClock.now" error. In order to eliminate any changes that I may have forgotten about, I worked up the simplest of examples that basically does nothing, and I still get this error when trying to run the test. See below for my simple example:
You can see that I do not even have a dependency on continuousClock in this example, yet I get the "Unimplemented: ContinuousClock.now" listed a bunch of times on my test function (i.e. the testDummy() line is highlighted in red and the error is listed six times...and it seems the number of times the error is listed changes each time I run the same test), and the test fails. Even if I override the continuousClock dependency with ImmediateClock, I get the same error. I am on the latest release of composable architecture 0.49.2, and XCode is showing v0.1.3 for swift-dependencies and v0.2.0 for swift-clocks libraries. Is this only happening to me? Did Gremlins get into my laptop over the weekend? I'm hoping someone might have some clues for me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @david-hosier, this most likely has to do with the fact that when tests run in an app target (as opposed to framework or SPM library) the simulator actually starts up and executes your application's code. So, that code will think it's in a test context and access non-overridden dependencies, causing the failures. Honestly, it's a huge gotcha that an application is running in the background, executing real life code. It means the simulator could be firing off network requests, tracking analytics events, and more, all without you knowing. TCA just happens to make this gotcha very in-your-face. The best solution is to extract out basically all code from the app target into frameworks/libraries, and then you can run tests on those targets more easily. However, that's a big change, so another idea is to wrap the entry point of your application in a This issue has come up enough times (see here) that we should probably have documentation on it. I will try to write up something soon. |
Beta Was this translation helpful? Give feedback.
Hi @david-hosier, this most likely has to do with the fact that when tests run in an app target (as opposed to framework or SPM library) the simulator actually starts up and executes your application's code. So, that code will think it's in a test context and access non-overridden dependencies, causing the failures.
Honestly, it's a huge gotcha that an application is running in the background, executing real life code. It means the simulator could be firing off network requests, tracking analytics events, and more, all without you knowing. TCA just happens to make this gotcha very in-your-face.
The best solution is to extract out basically all code from the app target into frameworks/libr…