Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在单元测试中传递函数名?_C++ - Fatal编程技术网

C++ 如何在单元测试中传递函数名?

C++ 如何在单元测试中传递函数名?,c++,C++,我正在开发一个基于线性代数概念的库。因此,我在业余时间分阶段构建开发套件。我遇到的问题之一是测试我应该得到的代码和输出 我有10个测试用例(例如),如下所示: template<typename T> void testDiag(T begin, T end) { // run test here and check } class TEST_CASE : public ClassX { public: template<typena

我正在开发一个基于线性代数概念的库。因此,我在业余时间分阶段构建开发套件。我遇到的问题之一是测试我应该得到的代码和输出

我有10个测试用例(例如),如下所示:

template<typename T>
void testDiag(T begin, T end)
{
    // run test here and check 
}
class TEST_CASE : public ClassX
{
     public:
           template<typename T> 
           TEST_CASE(T begin, T end, FUNCTION_NAME, EXPECTED_OUTPUT)
           {
               auto test_case = FUNCTION_NAME(begin, end); 

               // DO SOME COMPARISON 

               // output error or success 
           }

           int test1([interator])
           { 
               int output = // do something;
               return output; 
           }

     protected:

}
模板
无效测试诊断(T开始,T结束)
{
//在此处运行测试并检查
}
我真正想要的是一种方法(我不知道这是否可能)拥有一个类“TEST_CASE”,能够初始化所有的测试,然后有一种最终的方法运行所有的测试,但通过函数

大概是这样的:

template<typename T>
void testDiag(T begin, T end)
{
    // run test here and check 
}
class TEST_CASE : public ClassX
{
     public:
           template<typename T> 
           TEST_CASE(T begin, T end, FUNCTION_NAME, EXPECTED_OUTPUT)
           {
               auto test_case = FUNCTION_NAME(begin, end); 

               // DO SOME COMPARISON 

               // output error or success 
           }

           int test1([interator])
           { 
               int output = // do something;
               return output; 
           }

     protected:

}
类测试案例:公共类X
{
公众:
模板
测试用例(T开始、T结束、函数名称、预期输出)
{
自动测试案例=功能名称(开始、结束);
//做一些比较
//输出错误或成功
}
int test1([interator])
{ 
int output=//做点什么;
返回输出;
}
受保护的:
}

基本上,我会将迭代器传递给构造函数,也是一个执行测试的函数,还有一些预期的输出,然后进行比较并显示输出

您所做的与google测试框架类似,看看您是否在寻找函数指针(或成员函数指针或
std::function
)?