首页 > 解决方案 > googletest 错误:“HasSubstr”没有依赖于模板参数的参数

问题描述

我正在使用googletest我的程序(C++)测试。在其中一个测试中,我必须检查一个字符串是否存在于另一个字符串中,例如:

#include <gtest/gtest.h>

TEST_F(TestSet, substringCheck)
{
    string s1 = "the fruit is apple";
    string s2 = "apple";

    EXPECT_THAT(s1, HasSubstr(s2));
}

但它给了我这个错误:

error: there are no arguments to ‘HasSubstr’ that depend on a template parameter, so a declaration of ‘HasSubstr’ must be available

我不认为 googletest 有任何其他直接的方法来检查子字符串,所以我正在使用HasSubstr这个测试,任何人都可以指导:

  1. 错误提示什么?
  2. 如何解决?

标签: c++testinggoogletest

解决方案


推荐阅读