I have a C++ CLI test project in Visual Studio 2013 that calls native code;
[TestMethod]
void Test1()
{
int R1, R2;
R1 = R2 = std::numeric_limits<int>::max();
R1 = SyncPort::OpenPort(Channel, ReceiveChan, PortID, NominalBaud);
R2 = SyncPort::OpenPort(Channel, SendChan, PortID, NominalBaud);
Assert::AreEqual(spSuccess, R1);
Assert::AreEqual(spSuccess, R2);
};
For some reason, when I add the two OpenPort calls, the test disappears from Test Explorer and cannot be run. If I comment them out, the test appears again.
The SyncPort class is defined in a separate .LIB that is statically linked into the test project. If I define a mock replica class that has the same signature locally, it works. What am I doing wrong? Why doesn't MSTest like me adding external native functions in a test?
I fixed the problem. It was cause by the
SyncPortassembly having a missing delay-loaded dependency. Therefore the syntax was correct but it would never load. The test detection engine loads the test assembly in the background after compilation, which attempts to load theSyncPortassembly and fails.The solution was to fix the dependency issue and it all falls into place.