单元测试回波功能

时间:2020-03-31 21:29:46

标签: c++ unit-testing echo

更具体地说,我正在从事涉及单元测试的任务。这些是我目前正在处理的测试用例:

#include "c-echo.h"

#include "gtest/gtest.h"

TEST(EchoTest, HelloWorld) {
    char* test_val[3]; test_val[0] = "./c-echo"; test_val[1] = "hello"; test_val[2] = "world";
    EXPECT_EQ("hello world", echo(3.test_val));
}

TEST(EchoTest, EmptyString) {
        char* test_val[1]; test_val[0] = "./c-echo";
        EXPECT_EQ("", echo(1.test_val));
    }

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

c-echo.h程序:

#include <iostream>

std::string echo(int length, char** chars) {
    std::string ret = "";
    for(int i = 1; i < length; i++) {
        ret += chars[i];
        if(i < length - 1) {
            ret += " ";
        }
    }
    return ret;
}

该作业表明,我需要为回显功能添加三个其他测试用例(尤其是边缘用例)。但是,我似乎什么也没想。我真的是整个测试的新手。

谢谢

0 个答案:

没有答案