Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test Setting up MS Test

Setting up MS Test

Top  Previous  Next

Visual Studio 2012 and later versions come with a test framework for C/C++ called MSTest.

In order to set up a project, create a new project from the C++ path, of the type Native Unit Test Project:

 

MSTestSetup

 

Once the project is set, we'll add the steps need to incorporate Isolator++ Professional:

 

Including the .h file

 

Open the project properties. Add the Isolator++ Professional Include\ForTests folder to the include directories.

 

isolatorInclude

 

Add the IsolatorCore.lib to the linker input list. Note, we're using the x86 library, if we want the x64 bit we'll link to the library from the x64 folder.

isolatorLibLinker

 

As the last step, make sure to copy IsolatorCore.dll,symsrv.dll and msdia140.dll to the location of the tests executable path. We'll do it by using a post-build event (note that for the 64 bit version copy the dll from the x64 folder):

PostBuildCopyEvent

 

Once everything is set, you can start writing tests. In MS Test the code looks like this:

 

#include "CppUnitTest.h"

#include "Isolator.h"

#include "CodeYouWantToTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework

 

TEST_CLASS(MyTestSuite)

{

public:

 TEST_METHOD(TheTestName)

 {

         FAKE_STATICS<ClassWithStaticCalls>();

         WHEN_CALLED(ClassWithStaticCalls::StaticIntCall()).Return(1);

  

                   Assert::AreEqual(1, ClassWithStaticCalls::StaticIntCall());

                   ISOLATOR_CLEANUP();

 }

}

 

 

After compiling and running the test from the Test menu, you can see the tests in the Test Explorer window.


Copyright  Typemock Ltd. 2009-2023.  All Rights Reserved.