chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hello,
I have a project in CLI C++, can type mock be used for writing unit tests for CLI based C++? If yes, could someone help me on documentation as to how to do it?

I need to mock few objects in CLI-C++ to provide coverage.

Thanks in advance

ANAND.K
asked by meetanandan (3.2k points)

5 Answers

0 votes
Hi,

Isolator works with CLI C++, the best usage is though the C# API. Basically all needed to is to work with usual .NET unit tests projects as if the under test is a C# project. Is there a specific scenario you'd like to test?
answered by Elisha (12k points)
0 votes
Hi,
Thanks for your reply. My company has typemock purchased and we have so far used it for .net C#, but now we have interop component written in CLI-C++, that access a .net C# component. We would like to write unittest coverage for it. Is there any documentation or sample Type mock based program for CLI-C++?

Thanks,
ANAND.K
answered by meetanandan (3.2k points)
0 votes
Hi,

I haven't find documentation on this but you should be able to test it as if it was a regular C# project.

Please let me know if you encounter problems while writing tests.
answered by alex (18k points)
0 votes
Hi,
I tried to do it myself in c++...But I got a compilation error in the highlighted code. Could you please check this

[TestMethod]
void TestMethod1()
{

SampleCLI::Class1 tempClass;
MockObject^ mockClass1;
mockClass1= TypeMock::MockManager^ MockObject(System::Type^(SampleCLI::Class1));
mockClass1-> ExpectAndReturn("sum", true);

};

Error 1 error C2059: syntax error : ')' C:\project\sample program\Sample UT\Sample UT\UnitTest1.cpp 72 1 Sample UT


Could you tell me what is the mistake I am doing?

Thanks,
--- ANAND.K
answered by meetanandan (3.2k points)
0 votes
Hi Andan.

We encourage working with C# for tests rather than C++ for the reason you've bumped into : bad errors messages and lack of support of unit testing frameworks. That is part of the reason we don't supply C++ CLI examples - they are very fragile and we'd like users to not fall into these kinds of traps. Rather focus on testing with easy tools. Keep the C++ production code, but do the testing in C#.

The setup we suggest is this: create a C# test project. Reference the C++ CLI dlls, and continue writing the tests in c#. You can use the regular MSTest runner, or use the Typemock Test Runner.
answered by alex (18k points)
...