Can you create a supernet target in Xcode?

For unit testing, I would like to create an iPhone project goal in Xcode that includes all release application files, as well as some additional files containing code useful for testing the UI module.

I can do this by duplicating the original purpose of the application; however, the problem is that every time I add a new source file to the application, I need to also add it to the UnitTestUI target. It doesn’t matter, it’s just inconvenient to always forget to add files for both purposes.

Is there a way to configure the dependency so that every file added to the target of the application also automatically adds the unit test target?

+6
xcode dependencies target superset
source share
3 answers

In Xcode, you can create objects that have direct dependencies on each other. There are a number of non-product goals that can help in the Other category when adding a new goal, depending on how simple or complex your setup is. Creating specific goals for running unit tests that are directly dependent on the project’s main goal is very common and documented by Apple and on several blogs.

In your situation, however, you may have to tune in a lot to the new goal of testing the user interface, but after setting it up it will be very easy to maintain. Without knowing your exact situation, it is impossible to give you a step-by-step answer, but here are the general recommendations (customization according to your situation):

  • Make a copy of the original goal, as most of your settings will be the same.
  • Select a new target and open the inspector (⌘I)
  • In the Direct Dependencies section, click the + button and select the main target.
  • Set up a new goal as desired, with additional documentation / source / rules or whatever.

If you prefer to drag things, you can also drag the original target (from the Goal disclosure triangle) to the new target, and it will automatically adjust the dependency.

Now select the target audience as the active target and it will always build with these rules. In addition, if you add / modify the source code in the main target, it will be rebuilt correctly when creating the test target ... do not forget to add the source file to the test target. I suggest taking some time to read the various Xcode docs and play with the many targeted templates available ... ultimately, it really helps make the use of the product much more efficient. There are many great things you can do quite easily in Xcode if you know how, even with very large or complex projects.

+4
source share

No no. Is there any specific reason why you need every file in your target unit test program? This will include main.m and all classes that you are not testing (for example, your view classes). In fact, if main.m is included in your Unit Test, how would your Unit Test work normally?

0
source share

I solved the problem by creating most of my application as a static library, which is related to both target applications and unit test.

The goals in my project are:

  • libMyApp
    • compile .m files
  • Myapp.app
    • libMyApp (dependency)
    • Link to the library: libMyApp.a
  • UITest.app
    • libMyApp (dependency)
    • Link to the library: libMyApp.a

That way, I can add .m files only to the "libMyApp" target and make them available in both the application and the tests, and they don’t even need to recompile.

The only problem is that the static library does not seem to support Objective-C categories, so I still have to add them to each target separately.

0
source share

All Articles