Re: Unit testing and my OS X app
Re: Unit testing and my OS X app
- Subject: Re: Unit testing and my OS X app
- From: Joar Wingfors <email@hidden>
- Date: Mon, 14 Apr 2014 21:20:27 -0700
On 14 apr 2014, at 16:03, Rick Mann <email@hidden> wrote:
> I just added a unit test target to my OS X app. I had to jump through some hoops because it was signed, but I got it to work.
>
> Then it dawned on me that my app was being launched to run my unit tests. This brings up a couple of things:
>
> • Does it make sense to run the actual unit tests outside of my app? That is, I don't think I want to incur the startup costs of my app when running unit tests. Is there a generic bundle loader that is more light-weight? Barring that, can my app detect it's being launched for unit tests and skip a bunch of startup work?
As you later figured out, you can ask to have your tests execute inside of the otest/xctest command line test hosts. That said, there are several good reasons to prefer having your tests run inside of your app, or inside *some* app.
The otest/xctest command line test hosts doesn't work with:
- iOS devices (requires OS X / iOS simulator).
- Some things to do with sandbox or custom entitlements.
- Some frameworks use of linked-on checks.
In all of these cases, an application would work fine, and provide a more well defined execution environment.
> • I still had to link the classes used by the unit test into the unit test target. What's going on here? If it's running in the context of my app, why does it need to link against these files?
Not quite sure what you mean by "link the classes" here. Code in your application binary would be accessible to code in your test bundle without explicit linkage by way of the bundle loader build setting (which is set by default, at lest for new projects / targets).
That said, for this to work you need something like:
GCC_SYMBOLS_PRIVATE_EXTERN=NO
<https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html>
...at least for C++ code, and at least for the build configuration of your app target used when running tests (debug per default). The Stack Overflow post you mentioned later also mentions this.
On 14 apr 2014, at 16:18, Rick Mann <email@hidden> wrote:
> Ah, one question I forgot to add was, where is this documented? A google search turned up only the Xcode overview.
There is no documentation for XCTest as of this writing. The documentation for OCUnit has been marked as "legacy" (which makes it more difficult to find), but most of that still applies:
<https://developer.apple.com/legacy/library/documentation/DeveloperTools/Conceptual/UnitTesting>
> But I recalled reading about "logic" tests. I finally found a SO question that clarified it somewhat, and suggested removing the Bundle Loader and Test Host build settings, but comments there say that no longer works with Xcode 5.
>
> http://stackoverflow.com/questions/19219706/xcode-5-unit-testing-starts-my-app
What they're referring to in that Stack Overflow post is that execution of iOS tests targeting the iOS simulator now requires the iOS simulator app to be launched, where as you could avoid that in earlier versions of Xcode. There are good technical reasons for why this change was introduced. From an usability point of view I can understand if you may prefer to not have to see the iOS simulator pop-up while running unit tests.
Joar
_______________________________________________
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