24

Since application tests can now be run on the simulator from Xcode, what would the advantage be, apart from possibly a small saving in execution time, of still separating your tests into logic and application tests?

The differentiation as per the Apple docs:

  • Logic tests. These tests check the correct functionality of your code in a clean-room environment; that is, your code is not run inside an application. Logic tests let you put together very specific test cases to exercise your code at a very granular level (a single method in class) or as part of a workflow (several methods in one or more classes). You can use logic tests to perform stress-testing of your code to ensure that it behaves correctly in extreme situations that are unlikely in a running application. These tests help you produce robust code that works correctly when used in ways that you did not anticipate. Logic tests are iOS Simulator SDK–based; however, the application is not run in iOS Simulator: The code being tested is run during the corresponding target’s build phase.

  • Application tests. These tests check the functionality of your code in a running application. You can use application tests to ensure that the connections of your user-interface controls (outlets and actions) remain in place, and that your controls and controller objects work correctly with your object model as you work on your application. Because application tests run only on a device, you can also use these tests to perform hardware testing, such as getting the location of the device.

itsaboutcode
  • 24,525
  • 45
  • 110
  • 156
nduplessis
  • 12,236
  • 2
  • 36
  • 53
  • This question may be irrelevant since that link is dead. Take a look at http://stackoverflow.com/q/41404613/62 for more. – Liron Yahdav Dec 31 '16 at 01:40

1 Answers1

4

Application tests compared to logic tests are really used for two different things:

Logic tests/unit tests are used to test very small behavior for one or a few methods, e.g. "Given that I create my object like this, is the value of a certain property what I expect it to be?"

Application tests however are used to test the big picture, e.g. "Do I get the right data in my detail view when I tap on a certain table view cell?"

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • 1
    Sure, this is true, but what would I gain from separating these tests into different test files/bundles? – nduplessis Jul 18 '11 at 10:02
  • Just so we are talking about the same thing. I mostly mean UIAutomation tests in Instruments when I talk about application tests and unit tests in Xcode (OCUnit or alike) when I talk about logic tests. – David Rönnqvist Jul 18 '11 at 10:50
  • Well... it's easier to write small, detailed tests as logic tests, since you are closer to the code and a writing objective-c code, even though you could do some of them as application tests. The same thing is true the other way around. It becomes a question of using the right tool for the task at hand. – David Rönnqvist Jul 18 '11 at 11:06
  • OK so my question specifically pertains to application tests as described in http://developer.apple.com/library/ios/#DOCUMENTATION/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html, this excludes UI automation tests as implemented in Instruments – nduplessis Jul 18 '11 at 13:04
  • 1
    OK, in that case the difference really only is that Logic tests run on the simulator which makes it better suited for test which should run often, e.g. every build. Application Tests run on the device which makes it a little more cumbersome since the device needs to be connected. The upside is that you get access to device-only features like location. So application tests are more powerful but less convenient. – David Rönnqvist Jul 18 '11 at 13:56
  • I think that documentation might be a bit old because you can actually run application tests in the simulator, though not everything is supported – nduplessis Jul 18 '11 at 14:01
  • @DavidRönnqvist Actually, Application Tests can run on the simulator too. – Rudolf Adamkovič Dec 30 '12 at 21:32
  • 1
    One of the key benefits of Logic Tests is *speed*. You're not launching the simulator and other startup code in your app. – idStar Oct 31 '15 at 15:04