Putting tests in same file as code to be tested?
Putting tests in same file as code to be tested?
- Subject: Putting tests in same file as code to be tested?
- From: Rick Mann <email@hidden>
- Date: Wed, 27 May 2015 15:58:08 -0700
It occurs to me that for a certain class of code, having the unit test code in the same file can be very convenient. I have a great deal of utility code in the form of enhancements to existing UIKit or NS classes (usually in the form of categories adding functionality). This code is shared among several projects. As work progresses on a given project, this shared code is often added to. It would be nice to include the test code for these classes in the same file, so that the tests could get run all the time, and updated to keep up with changes. The alternative is to have a separate project for the common code. But this makes it harder to include just the bits one needs in the parent project, and raises issues on iOS with linking.
So, being able to include the unit tests right with the code to be tested would be nice. The downside, of course, is that the test code normally gets linked in with the distributed binary if you do this.
I'm wondering if there's not a way to coerce Xcode into stripping out test code when building the final binary, despite being in the same translation unit. One could do it with guard macros, but that seems clunky, and forces a complete rebuild when you want to build one version or the other. Can linker sections be used, or some kind of post-build script, to remove test code?
Does this seem like a feature worth requesting?
--
Rick Mann
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden