2012-06-01 45 views
1

如何在Objective C單元測試中添加構造函數?如何在客觀c單元測試中添加構造函數?

隨着defaut Xcode的測試代碼:

#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"); 
} 

它可以添加構造在該文件中所有的測試?

* 編輯:* 在我的情況下,它是測試一個webService調用的resutl。 在構造函數中,我調用webService並且每個測試都測試答案。 但是如果我在setUp中調用webService,它會調用每個測試。

由於

+0

沒有更多的信息就無法回答這個問題。你想要構建什麼?測試夾具?你不需要。你正在測試的對象?這可以在'-setUp'或測試方法中完成。還有別的嗎? – 2012-06-01 12:37:25

+0

我已編輯我的問題 – Anthone

+0

請參閱http://stackoverflow.com/questions/3630339/sentestkit-cleaning-up-after-all-tests-have-run –

回答

1

setUp方法是排序構造的單元測試。它在每個test方法之前被調用。 tearDown同樣適用於單元測試的「析構函數」。

+0

感謝您的回答。但是如果我需要準備每個測試例如調用一個webService。使用這種方法,我會爲每個測試調用它。 – Anthone

0

GHUnit是一個擴展的OCUnit的有:

  • (無效)setUpClass
  • (無效)tearDownClass

您可以使用這些像一個構造函數和析構函數。

相關問題