I want to do an Application test that parses some json, stores to core data, and reads out some objects.
How can my code know if it's being run as part of a test or normal run? Just some way to know "are we in test target"? Because the app when it fires up now kicks off a bunch of requests to populate my coredata with info from the server. I don't want it to do this during my tests. I want to fire up the App, read HARDCODED json from a file and store this using the same methods as otherwise into coredata, and verify the results.
If someone could explain how to pass specific key-value pairs on a per target basis that can be read from within the app, I would be even more delighted.
Click on the project (the very first object in the tree) in the project navigator and you'll get a view with project settings on the right and targets on the left.
And now in Swift, you may call AppTargetName() and get your target name, without need to modify Info.
A target defines a single product; it organizes the inputs into the build system—the source files and instructions for processing those source files—required to build that product. Projects can contain one or more targets, each of which produces one product.
A Target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.
Never mind... figured out that it is in "Schemes" that you set this.
For example if you want TARGET=TEST to be available during Test and TARGET=RUN to show during run, just set that in your Scheme > Environment Variables > Name/Value.
Then from your app you can do:
[[[NSProcessInfo processInfo] environment] objectForKey:@"TARGET"]
Using build settings with preprocessor macros DID NOT work for me b/c my test target (for application/integration testing) is dependent on my main (not test) target, so the main target is built first and that's what runs, and you end up with main target preprocessor macros even though you are after the ones defined in the target you ran. If I missed something here someone feel free to explain please.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With