1

How can I add constructor in Objective C unit test ?

With the defaut xcode testing code :

#import "MultiVueTests.h"

@implementation MultiVueTests

- (void)setUp
{
    [super setUp];

    // Set-up code here.
}

- (void)tearDown
{
    // Tear-down code here.

    [super tearDown];
}

- (void)testExample
{
    STFail(@"Unit tests are not implemented yet in MultiVueTests");
}

It's possible to add Constructor for all test in this file?

*EDIT : * In my case it's to test the resutl of a webService call. In the constructor I call the webService and each test testing the answer. But if I call the webService in the setUp, it will call for each test.

Thanks

Anthone
  • 2,156
  • 21
  • 26
  • It's impossible to answer this question without some more information. What do you want to construct? The test fixture? You don't need to. The object you're testing? That can be done in `-setUp` or in the test methods. Something else? –  Jun 01 '12 at 12:37
  • See http://stackoverflow.com/questions/3630339/sentestkit-cleaning-up-after-all-tests-have-run – Rob Napier Jun 04 '12 at 16:16

2 Answers2

1

The setUp method is sort of constructor for unit tests. It is getting called before each test method. Same goes for tearDown which serves as "destructor" of unit test.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
  • Thanks for your answer. But if I need preparation for each test for exemple calling a webService. With this method I call it for each test. – Anthone Jun 04 '12 at 15:54
0

GHUnit is an extension of OCUnit that has:

  • (void)setUpClass
  • (void)tearDownClass

You use these like a constructor and a destructor.

Howard Lovatt
  • 968
  • 1
  • 8
  • 15