SenTestKit: cleaning up after ALL tests have run?

折月煮酒 提交于 2019-11-28 21:34:40

Don't run your command-line tool in +initialize. That's sent by the Objective-C runtime when the class is first sent any message.

Instead, run your command-line tool in your test's +setUp method. (Note that I really did mean +setUp and not -setUp; lots of folks seem to be a bit fuzzy on the difference between class and instance methods.)

In this case, a class setUp method is invoked by OCUnit before any of tests in a SenTestCase subclass are run, and a class tearDown method is invoked by OCUnit after all tests in a SenTestCase subclass ar run.

So the overall flow for a particular SenTestCase subclass is:

  • send +setUp to SomeTestCase
  • for each test method starting in SomeTestCase (call it test___)
    • create a new instance of SomeTestCase
    • send -setUp to it
    • send -test___ to it
    • send -tearDown to it
    • release it
  • send +tearDown to SomeTestCase

This way if you have something that needs to be done before any of your -test methods run, or something that needs to be done after all of your -test methods run, there's a deterministic point at which you can make that happen. (Rather than rely on memory management, which isn't deterministic in the same way, and may not be deterministic at all if you're using GC.)

You should look at Google Toolbox for Mac or its further derivative GHUnit. Both (I think) provide class-level setup and teardown at least. If you really want to run a command-line before all tests are run and then a second command line (perhaps to kill the first) after tests are run, I would modify the shell script build phase that runs the unit tests (the last step in a UnitTest bundle target's build phases).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!