开发者

Visual C++ Team Test problems

开发者 https://www.devze.com 2022-12-11 23:50 出处:网络
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:

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();

  开发者_如何学Go }
 };
}
namespace TestProject1 {

}

The same exact problems happen on every install of VSTS I tried.


I've just set up a simple test test using MS VS Test and I could get it to run. Here is the project:

http://www.somethingorothersoft.com/TestTest.zip

I guess whatever problem you having is to do with the definition of MShape.

Alternatively, you could just test your unmanaged code directly inside tests. You will need to change the test project's CLR Support from /CLR:Safe to /CLR and then just run straight C++ in your tests.

I tried to include that capability in the demo but I couldn't get both kinds to run in the same project - i.e. both using a managed wrapper and one without from the same target project. If you make undertest project a static library and remote CLR support, you will be able to run unamanged code from it in your test project.

0

精彩评论

暂无评论...
验证码 换一张
取 消