开始用C++/CLI做项目,但默认生成的UnitTest在项目中使用了C++代码时会出错。这个问题在困扰了我两天后,终于找到了答案,共享之。

     Then you can write Unit Tests by hand as: [TestClass] public ref class TestClass {public: [TestMethod] void Test() {} }; You can use full power of unmanaged C++, call your native code directly, etc inside your Unit Tests.

The are other options but I would say you don't want to do that:
- Write managed C++ wrapper and auto-generate Unit Tests for the managed C++ wrapper.
- Create new VB, C# or MC++ Test Project and call your unmanaged code from test methods using [DllImport].
- If your C++ code is COM typelib, you could register the lib, and could add the lib to your test project's references (via COM tab in Add references dialog). Then you can exercise your C++ code in managed test code.

Thanks,
Michael


相关文章:

  • 2021-08-01
  • 2021-08-29
  • 2021-09-08
  • 2021-10-26
  • 2021-10-15
  • 2022-12-23
  • 2021-07-10
  • 2021-10-18
猜你喜欢
  • 2021-12-20
  • 2021-12-16
  • 2021-05-17
  • 2021-06-28
  • 2022-01-31
  • 2022-12-23
  • 2022-03-02
相关资源
相似解决方案