0

I am writing Objective-C unit tests in Xcode. I would like to extend my base class so I can reuse my setUp/tearDown methods. I created a header and put the imports there, since Xcode defaults to making just an implementation file.

Extending the base class works fine, except that all of its test methods are run a second time (or n times, depending on number of children).

My question is if this is the appropriate practice, or should I try something like base classes with no test methods?

owenfi
  • 2,471
  • 1
  • 24
  • 37
  • 1
    I'd normally make separate test classes instead of putting the tests right inside the classes. That makes it easier to separate what code should be in a production build, and cleanly separates testing concerns from functionality (ie inheritance is not a problem). – Joachim Isaksson Aug 18 '13 at 09:30
  • 1
    Running the same test more than once is a waste of time. I would create a "base" class that only implements the setUp and tearDown methods. – Matthias Bauch Aug 18 '13 at 09:40
  • Joachim, sorry if I wasn't clear, the tests are not in the class under test (you make a good point about keeping production code separate). Thanks Matthias, I may go that route, but it seems odd to me (coming from a more jUnit background, I don't think it happens that way there). – owenfi Aug 18 '13 at 20:46

0 Answers0