Running unit test without simulator

Is it possible to run business logic (e.g. non-UI) unit tests without triggering the simulator?
Someone said if I add all the tests into a framework, then it won't trigger the simulator. As a Swift beginner, not sure what that means. A framework in Swift is like a library in Java/.net?

UI tests involve simulators. Unit tests do not. You need to add a unit test target to your project. That's where you put your non-UI tests.

My unit tests do have a test target; when I created a new project in xcode, I choose "include test" option and it automatically created two test targets; one for unit test and one for UI tests. But even when I am running the unit tests, it still loads the simulator.

Whatever kind of target you have, running tests on iOS, unit or UI, necessarily involves running the simulator. If you want to make your framework cross platform and support macOS, you can run on that platform instead, but that's usually not a viable approach to the problem.

3 Likes

Thanks for the reply.
Two questions:

  1. how to make it work? e.g. how to run framework tests without the simulator? I tried to create a framework and run its tests; but it still triggered simulator.
  2. You mentioned this usually is not a viable approach, why?

You mentioned this usually is not a viable approach, why?

Because all code is built for a platform, with macOS, iOS, and the iOS simulator being different platforms. The only way to run iOS code on the Mac [1] is to build it for the iOS simulator platform, and the iOS simulator platform can only run within a simulator.

The easiest fix here is to do what Jon_Shier suggested, that is, allow your framework to build for the Mac. That’s usually pretty straightforward for non-UI frameworks.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

[1] Well, that’s not quite true. Apple silicon Macs can run iOS apps via iOS Apps on Mac, but this isn’t the direction you want to go.