[英]How to test a function only defined in CPP file with GoogleTest
I'm new with GoogleTest framework and I have an issue related to testing utility methods that are only defined in the CPP file.我是 GoogleTest 框架的新手,我遇到了与仅在 CPP 文件中定义的测试实用程序方法相关的问题。 In the following example I would like to test the function baz
without exposing it through the .hpp
file.在下面的示例中,我想测试函数baz
而不通过.hpp
文件公开它。 What would be the best approach?最好的方法是什么?
// .hpp
namespace ns {
void foo();
void bar();
}
// .cpp
#include ".hpp"
void baz() {
}
namespace ns {
void foo() {
baz();
}
void bar() {
baz();
}
}
You don't need to expose baz
through the .hpp file.您不需要通过 .hpp 文件公开baz
。 You can declare void baz();
您可以声明void baz();
in any file before its usage.在使用之前的任何文件中。 Even inside a function, like即使在函数内部,例如
void foobar() {
void baz();
baz();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.