2014-01-24 23 views
0

我使用Netbeans Test創建函數創建了我的第一個測試類,並通過了所有測試。如果cppunit成功,在控制檯中輸出消息

現在我想打印終端窗口中的「成功」,如果測試x通過。

我想是這樣的:

void test(bool testResult) 
{ 
if(testResult==true) 
cout << "Success"; 
} 

參數TestResult中應該是測試x的結果。

但是我在哪裏以及如何獲得該狀態?

如何查看main中的測試狀態?

更新: 我得到現在這個:

void test(bool testResult) 
{ 
if(testResult==true) 
{ 
    cout << "Success"; 
}else cout << "Failure"; 
} 



int main(int argc, char** argv) 
{ 
.... 
test(newtestclass); //included my testclass.h and put the test class as parameter 
} 

我現在只得到1錯誤Netbeans中: 「的main.cpp:59:22:錯誤:預期前主表達式 ')' 標記」

回答

0

你主要是參考一個方法。試試這個:

test(); 

Main()或任何,在那裏你會覺得它應該工作!但記得要始終包含在方法內部參數,如:

Main(/* anything */) { 
    bool x = true; 
    test(x); 
} 

這樣,代碼將執行,並在開始的時候會去的方法,並且將執行它!它將使用x bool的值,並且將按照您爲其編寫的方法運行!

其次,

if(testResult == true) { 

的含義

if(testResult) { 

第二方法更好和更短的相同。

+0

我用我的最新代碼更新了我的問題。不知道如何在評論中使用代碼。 4空格不使用代碼格式。 – d0zer