Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

unit testing - SenTestKit: cleaning up after ALL tests have run?

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

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...