我正在尝试使用Visual Studio Test Suite运行本机C ++的单元测试。我只有一个名为“Shape”的简单类。我按照教程进行了以下步骤:
现在我遇到以下问题:
当我尝试编译测试项目时,C ++编译器崩溃了。这条线是罪魁祸首:
MShape_Accessor ^ shape = gcnew MShape_Accessor();
如果我右键单击并选择Go to definition,VS表示符号未定义。
以下是MShapeTest.cpp的完整代码(由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 {
}
在我尝试的每次安装VSTS时都会发生同样的问题。
答案 0 :(得分:1)
我刚刚使用MS VS Test设置了一个简单的测试测试,我可以让它运行。这是项目:
http://www.somethingorothersoft.com/TestTest.zip
我猜你遇到的任何问题都与MShape的定义有关。
或者,您可以直接在测试中测试非托管代码。您需要将测试项目的CLR支持从/ CLR:Safe更改为/ CLR,然后在测试中直接运行C ++。
我试图在演示中包含该功能但我无法在同一个项目中运行这两种类型 - 即使用托管包装器和不使用同一目标项目的那种。如果您使undertest
项目成为静态库和远程CLR支持,您将能够在测试项目中运行未管理的代码。