Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target individual XCTest unit test cases in Xcode 5 to a specific iOS device for a universal app?

I'm building a universal iPhone/iPad application, and the UI is significantly different in some cases (i.e. on iPhone we use a Master/Detail paradigm with TableViews, whereas on iPad we're using a CollectionView with cells that contain the details).

Because the interfaces are so different, it changes how the unit tests for the view controllers are constructed. In the collection view, we'd have to test to make sure the cells get built correctly and contain all the detailed information, whereas on iPhone we'd need two sets of tests - one for the master list and one for the detail screen.

So my question is, in a universal application being built using Xcode 5 with XCTest framework, can you target individual unit test cases / classes to be run on specific physical devices?

I came across a similar question here - iOS Unit testing universal application - but the asker had different intentions and was using older technologies.

I've also seen recommendations to do a check in individual test functions for UserInterfaceIdiom but that seems really crude. Ideally, there would be an annotation that would designate specific tests run on specific devices, or be able to designate an entire test class for a specific device.

Thanks in advance for your suggestions.

--EDIT--

@TommieC led me down what seems to be the appropriate path, if a smidge manual. I created two new testing specific schemes, one for phone-sized devices, and one for tablet-sized devices. Inside those schemes, I edited the test portion and added in the core tests along with the device-specific tests.

I then have jenkins execute two build steps, targeting the appropriate devices to test for the particular scheme. The downside to this approach is two build steps. However, I plan to split up the jenkins job and run it on 2 slaves with the appropriate devices hooked to each to parallelize the testing.

AFAIK this will also be Xcode Build Services friendly, as it works based off of schemes in a project as well. It's really too bad there isn't something more elegant built into XCTest for this, considering this doesn't scale terribly well in the event a new device type comes into play (watch/tv/hair dryer/etc.)

like image 295
Matt S. Avatar asked Oct 25 '13 15:10

Matt S.


People also ask

How do I run XCTest in Xcode?

To run your app's XCTests on Test Lab devices, build it for testing on a Generic iOS Device: From the device dropdown at the top of your Xcode workspace window, select Generic iOS Device. In the macOS menu bar, select Product > Build For > Testing.

What is XCTest in Xcode?

Overview. Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow. Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren't satisfied.

How do I add unit tests to an existing Xcode project?

To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.


1 Answers

To target device specific tests one would need to edit the schemes for a project. Under Product > Scheme > Edit Schemes one can choose to select device specific tests per device.

Scheme Editor

like image 107
Tommie C. Avatar answered Sep 28 '22 13:09

Tommie C.