SenTestKit:运行完所有测试后清理吗? [英] SenTestKit: cleaning up after ALL tests have run?

查看:67
本文介绍了SenTestKit:运行完所有测试后清理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode中使用SenTest进行单元测试.我必须为我的单元测试运行一个命令行任务.我可以在我的测试类(当然是SenTestCase的子类)的+ initialize方法中做到这一点.

I am using SenTest in XCode for my unit tests. I must run a command-line task for my unit tests to test. I can do that in the +initialize method of my test class (subclass of SenTestCase, of course).

测试完成后,我想终止命令行任务.由于没有+ initialize的对立面,所以我很困惑.

I would like to terminate the command-line task when the tests are done. Since there's not an opposite of +initialize, I'm stumped.

是否有某种方法可以继承SenTest类来实现我所忽略的呢?

Is there some way to subclass a SenTest class to do this that I'm overlooking?

推荐答案

请勿在+ initialize中运行命令行工具.当类首次发送 any 消息时,由Objective-C运行时发送.

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.

相反,请在测试的+setUp方法中运行命令行工具. (请注意,我确实的意思是+setUp而不是-setUp;很多人似乎对类和实例方法之间的区别有点模糊.)

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.)

在这种情况下,在运行SenTestCase子类中的任何测试和类之前,OCUnit会调用 setUp方法 tearDown方法是在SenTestCase子类中运行所有测试后由OCUnit调用的.

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.

因此,特定SenTestCase子类的总体流程为:

So the overall flow for a particular SenTestCase subclass is:

  • +setUp发送到SomeTestCase
  • 对于从SomeTestCase开始的每个test方法
  • (将其称为test___)
    • 创建SomeTestCase
    • 的新实例
    • 发送-setUp到它
    • 发送-test___到它
    • 发送-tearDown到它
    • 释放它
    • 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

      这样,如果您需要在运行任何-test方法之前执行某些操作,或者在所有-test方法运行之后需要进行某些操作,则可以在确定性的意义上进行操作那发生了. (而不是依靠内存管理,内存管理不是以相同的方式确定性的,如果使用GC,则可能根本不是确定性的.)

      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.)

      这篇关于SenTestKit:运行完所有测试后清理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆