Is it possible to test “internal” class from a c++ dll using MSTest?

前端 未结 3 939
遥遥无期
遥遥无期 2021-02-08 21:52

We are currently trying to add unit testing to our c++ application. The application is made of 30 projects that generate 29 dll and 1 exe. We use MSTest to run our unit test sin

3条回答
  •  灰色年华
    2021-02-08 22:43

    Well don't shoot the messenger.

    • Visual Studio Unit testing (aka tests that run with MSTest.exe) only test managed code. You can't test unmanaged C++. There is a new native unit testing framework coming with VS11 (the next version).
    • InternalsVisibleTo like you said also applies only to managed code.
    • IMHO You usually don't need to test internal classes. Just like private types or methods, you test them via the public/exposed methods that use them. So if PublicA.Method1() is the way your clients would exercise InternalHelper.Method2() ; then I rely on the test for PublicA.Method1() to tell me if either of them is broken.
    • If you must test internal classes, try making them public (if methods are sufficient complex.. see MethodObject refactoring). Or you could make the test classes a friend of the internal classes.

    .

    class ProductionSUT
    {
      // production code to be tested
      friend class TestProductSUT;
    }
    

    Disclaimer: Haven't tried this out.. so may need some tweaks to pacify the compiler.

提交回复
热议问题