TestPlugInRunnerd.exe +格莫克

发布于 2024-10-24 12:47:53 字数 1070 浏览 3 评论 0原文

我们将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2024-10-31 12:47:53

首先,你不可能没有主电源。否则你将如何执行你的单元测试?

其次,您可以创建一个类的静态变量,在其中调用这两个函数,如下所示:

struct GmockInitializer
{
  GmockInitializer()
  {
    ::testing::GTEST_FLAG(throw_on_failure) = true;
    ::testing::InitGoogleMock(0,0);  // << not sure about this. might not work
  }
};
GmockInitializer gmockInitializer;

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 :

struct GmockInitializer
{
  GmockInitializer()
  {
    ::testing::GTEST_FLAG(throw_on_failure) = true;
    ::testing::InitGoogleMock(0,0);  // << not sure about this. might not work
  }
};
GmockInitializer gmockInitializer;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文