【问题标题】:Print Message in Console if cppunit is successful如果 cppunit 成功,则在控制台中打印消息
【发布时间】:2014-01-24 18:11:34
【问题描述】:

我使用 Netbeans 测试创建功能创建了我的第一个测试类,并且所有测试都通过了。

如果测试 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
}

我现在在 Netbeans 中只有 1 个错误: “main.cpp:59:22: 错误: ')' 标记之前的预期主表达式”

【问题讨论】:

    标签: c++ unit-testing testing cppunit


    【解决方案1】:

    您主要是在引用一个方法。试试这个:

    test();
    

    Main () 或任何你认为它应该工作的地方!但请记住始终在方法中包含一个参数,例如:

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

    这样,代码将执行,一开始它会去寻找方法,然后执行它!它将使用 x bool 的值,并按照您为其编写的方法运行!

    其次,

    if(testResult == true) {
    

    含义相同
    if(testResult) {
    

    第二种方法更好更短。

    【讨论】:

    • 我已经用我的最新代码更新了我的问题。不知道如何在 cmets 中使用代码。 4 个空格不能使用代码格式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多