4

I have been using OCUnit for unit testing in a project. I've managed to do all the setup required for OCUnit in Xcode 4.2 & successfully build my test cases.

How can I control the order (priority) for a test case? I see that test cases are built in alphabetic order of their name, i.e. if I have test method testA, testB, testC, they'll be executed in that same order.

What I need is for "testC" in the above example to be executed before "testB", as my method has some setup for variables & preferences for "testB", as well as core data entry, included in "testC".

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Ritika
  • 593
  • 1
  • 8
  • 21

1 Answers1

4

Either your make your test cases self-contained, so that they can run on their own without pre-conditions, or you name your test methods accordingly as you mentioned.

test0First, test1Second

I would recommend to make them self-contained. It's a little overhead, but you can implement reusable methods in your test case (that don't start with test) to make your life easier.

If you want a framework with more features check out GHUnit

  • Isnt there any other way out because i cant make all of my test cases atomic – Ritika Mar 16 '12 at 11:07
  • 2
    You can do it, you can make each test self-contained. It may take some pain to get there - for example, adding extra seams so that you redirect your writes to a fake data store - but this is a must-fix. – Jon Reid Mar 26 '12 at 00:16