TestPlugInRunnerd.exe +格莫克
我们将 cppunit 单元测试构建为 dll 并将其加载到 TestPlugInRunnerd.exe 中以显示我们的结果。我们编写自己的模拟,但我想开始使用模拟框架,例如 gmock。
我下载了 gmock 并链接到它,没有出现太多问题。我使用 gmock 编写了一个模拟,它编译得很好。但后来我在 gmock 常见问题解答中读到了以下内容:
If you want to use something other than Google Test (e.g. CppUnit or CxxTest) as your testing framework, just change the main() function in the previous section to: int main(int argc, char** argv) { // The following line causes Google Mock to throw an exception on failure, // which will be interpreted by your testing framework as a test failure. ::testing::GTEST_FLAG(throw_on_failure) = true; ::testing::InitGoogleMock(&argc, argv); ... whatever your testing framework requires ... } This approach has a catch: it makes Google Mock throw an exception from a mock object's destructor sometimes. With some compilers, this sometimes causes the test program to crash. You'll still be able to notice that the test has failed, but it's not a graceful failure.
我显然没有 main.c 文件。我需要做什么才能让 gmock 与我的 dll 一起工作?我应该考虑 gmock 的替代品吗?
谢谢,
巴里
We build our cppunit unittests as a dll and load it into TestPlugInRunnerd.exe to show our results. We write our own mocks but I'd like to start using a mocking framework such as gmock.
I downloaded gmock and linked against it without much in the way of problems. I have written a mock using gmock and it compiles fine. But then I read the following in the gmock faq:
If you want to use something other than Google Test (e.g. CppUnit or CxxTest) as your testing framework, just change the main() function in the previous section to: int main(int argc, char** argv) { // The following line causes Google Mock to throw an exception on failure, // which will be interpreted by your testing framework as a test failure. ::testing::GTEST_FLAG(throw_on_failure) = true; ::testing::InitGoogleMock(&argc, argv); ... whatever your testing framework requires ... } This approach has a catch: it makes Google Mock throw an exception from a mock object's destructor sometimes. With some compilers, this sometimes causes the test program to crash. You'll still be able to notice that the test has failed, but it's not a graceful failure.
I obviously don't have a main. What do I need to do to get gmock to work with my dll? Should I consider alternatives to gmock?
Thanks,
Barry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你不可能没有主电源。否则你将如何执行你的单元测试?
其次,您可以创建一个类的静态变量,在其中调用这两个函数,如下所示:
First, it is not possible that you don't have a main. Otherwise how would you execute your unit tests?
Second, you could create a static variable of a class where you call these two functions, like this :