nsscreencast / comments

Public comments on NSScreencast.com
0 stars 0 forks source link

Detect When Running Tests in Your AppDelegate #176

Open subdigital opened 3 years ago

subdigital commented 3 years ago

Written on 05/24/2018 15:34:08

URL: https://nsscreencast.com/episodes/341-detect-testing-in-app-delegate

subdigital commented 3 years ago

originally written by Jeff Remer on 06/07/2018 21:55:05

I recently went through the exercise of changing a non-hosted unit test bundle to an application hosted test suite. We have a lot of source files and doing the former required building all of those source files into both the app and the test suite, sometimes resulting in duplicate compilation. Switching to a hosted suite and just importing the app module resulted in 40% faster build time. The approach I took was _very_ similar to this one except instead of relying on an Xcode provided environment variable I just set one ("UNIT_TESTING") in the scheme under the Test phase then grabbed it from NSProcessInfo.

We have a mixed Swift and Objective-C app so we still have a main.m - in order to keep the main app delegate entirely isolated I switched around between an empty test app delegate and the real one in main.m.

subdigital commented 3 years ago

originally written by subdigital on 06/08/2018 02:33:11

That’s a really good point. I would have assumed at first that maybe the non-test-host version would be faster to run because the simulator is not involved, but since you have to build everything twice I guess that’s not the case.
Thanks for writing in about your experiences, as it will certainly help others who watch this series.

subdigital commented 3 years ago

originally written by Jeff Remer on 06/08/2018 15:38:13

Thanks for the reply! Yeah, in our case it happens to be faster just because we have a pretty large (hundreds of thousands of LOC), old (7 years), mostly monolithic (one big app module, a handful of smaller ones) codebase. I imagine it varies with architecture and application size. I'm working through modularizing our app more and more, often pulling out code into smaller frameworks. What's great is that they can just be tested with non-hosted unit test suites that still don't need to compile the source files twice because the related test target can just import the framework module. While I've read Uncle Bob's Clean Architecture your SOLID videos have really been helpful for thinking of practical ways to decouple the app.

subdigital commented 3 years ago

originally written by Idris Raja on 06/20/2018 17:11:43

that's pretty interesting. I did something similar by making a TestingAppDelegate like so: http://idrisr.com/2018/06/1.... I think your approach is cleaner though, and now I understand that the main objective is to prevent anything from becoming the RootViewController.