I am trying to get some unit tests for native C++ running with Visual Studio Test Suite. I have just a single, simple class named "Shape". I followed a tutorial and did the following steps:
- Created a "ref class" wrapper called "MShape" for the native class I want to test
- Changed configuration type to .dll
- Changed CLR support to /CLR
- Set Linker "Profile" to /PROFILE
- Recompiled successfully
- Added a Visual C++ Test Project
- Added a new unit test using the Unit Test Wizard
- In the wizard, selected the methods I want to test
Now I have the following problems:
- Visual Studio reports that most unit test generation failed because "Failed to compare two elements in the array"
The C++ compiler crashes when I attempt to compile the test project. This line is the culprit:
MShape_Accessor^ shape = gcnew MShape_Accessor();
If I right-click and select Go to definition, VS says the symbol is undefined.
Here is the full code for MShapeTest.cpp (generated by Visual Studio):
#include "StdAfx.h"
#include "StdAfx.h"
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace TestProject1 {
using namespace System;
ref class MShapeTest;
/// <summary>
///This is a test class for MShapeTest and is intended
///to contain all MShapeTest Unit Tests
///</summary>
[TestClass]
public ref class MShapeTest
{
private: Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public: property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
{
Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
{
return testContextInstance;
}
System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
{
testContextInstance = value;
}
}
#pragma region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//public: [ClassInitialize]
//static System::Void MyClassInitialize(TestContext^ testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//public: [ClassCleanup]
//static System::Void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//public: [TestInitialize]
//System::Void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//public: [TestCleanup]
//System::Void MyTestCleanup()
//{
//}
//
#pragma endregion
public: [TestMethod]
[DeploymentItem(L"TP4.dll")]
void MShapeConstructorTest()
{
MShape_Accessor^ shape = gcnew MShape_Accessor();
}
};
}
namespace TestProject1 {
}
The same exact problems happen on every install of VSTS I tried.