Test Target vs Test Class

Hi, I'm wondering when should create a new test target, and when to create a new test class while doing testing.


I have seen a lot of tutorial teaching how to do the test.


However, none of any tutorial/source ever mention in what situation which one to be created, or what are the difference.


Hope that somebody can give me an idea about that and probably some cases then you have encounter.


Thanks in advance.

Accepted Reply

In general, I recommend that you favour test classes over test targets because they are substantially more lightweight. However, there are some circumstances where multiple test targets make sense:

  • In some cases your tests require different target-level settings. An obvious example of this is UI tests vs normal tests; these absolutely need to be in different test targets.

  • In other cases it might make sense to separate tests on a target level due to the internal organisation of your code.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

In general, I recommend that you favour test classes over test targets because they are substantially more lightweight. However, there are some circumstances where multiple test targets make sense:

  • In some cases your tests require different target-level settings. An obvious example of this is UI tests vs normal tests; these absolutely need to be in different test targets.

  • In other cases it might make sense to separate tests on a target level due to the internal organisation of your code.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"