You are here: Home Development OS X Objective-C OCUnit

OCUnit

Information relating to the Objective-C unit test framework

otest

Initial execution is of the otest tool.  This is a command line tool that takes arguments of the bundle to load and test, and what should be tested in that bundle.

Comand line args are:

  • -SenTest [Self | All | None]
  • <TestCaseClassName/testMethodName>
  • <path/to/testBundle.otest>

 
Unfortunately, several environment variables are needed as well.

  • SenTestTool: 
    • sets the NSUserDefaults with:
      • SenTest:Self 
    • loads the test bundle (as passed in on the command line)
    • runs one of (if the test bundle loaded):
      • runTestFromBundle:
      • launchTaskFromPath:bundle: (if runTestFromBundle: returns false)
    • runs launchTaskFromPath:bundle: (if the bundle did not load)
  • SenTestTool: - (BOOL) runTestFromBundle:(NSBundle *)aBundle
    • sets the NSUserDefaults with:
      • SenTestedUnitPath:{the path of the passed in bundle} 
    • loads the bundle
    • Calls SenTestProbe +(void)runTests:
  • SenTestTool: -(void) launchTaskFromPath:(NSString *)aPath bundle:(NSBundle *)aBundle (this seems to be used instead of runTestFromBundle: when the bundle is determined from a class, and not from a command line argument)
    • determines the bundle the from the path
    • creates an NSTask and executes it, which has the effect of calling runTestFromBundle:

 

SenTestingKit 

At this point,execution leaves otest and goes into the framework.

  • SenTestProbe +(void) runTests:(id)ignoredValue;
    • Sends the selector principalClass to all frameworks
    • Loads the SenTestObserver class.  This registers the following notifications with the default notification center:
      • SenTestSuiteDidStartNotification
      • SenTestSuiteDidStopNotification
      • SenTestCaseDidStartNotification
      • SenTestCaseDidStopNotification
      • SenTestCaseDidFailNotification
    • calls run on the specifiedTestSuite. This is one of the following three (based upon the command line argument):
      • [SenTestSuite defaultTestSuite]
      • [SenTestSuite testSuiteForBundlePath:[self testedBundlePath]]
      • [SenTestSuite testSuiteForTestCaseWithName:testScope]
    • Calls hasSucceeded on the result of above.
  • SenTest +(SenTestRun *)run;
    • creates a SenTestSuiteRun instance initialized with the SenTestSuite
    • calls performTest:SenTestSuiteRun on self
  • SenTestSuite - (void) performTest:(SenTestRun *) aTestRun;
    • calls setUp on self
    • calls start on aTestRun
      • fires SenTestSuiteDidStartNotification
    • Calls run on each test in [self tests] (all the tests as defined in the specifiedTestSuite from above)
    • calls addTestRun: on aTestRun with the result of the above run call.
    • calls stop on aTestRun
      • fires SenTestSuiteDidStopNotification
    • calls tearDown on self

Document Actions
« September 2010 »
September
MoTuWeThFrSaSu
12345
6789101112
13141516171819
20212223242526
27282930