I am working with Microsoft Visual Studio 2012 Ultimate to write C++ applications. I got that version from my MSDNAA access. My Problem is that I want to create unit tests for the C++ classes I wrote.
Please Note: It's standard conform C++, nothing mixed, no C#, it's just C++ that can also be compiled with the g++.
Under file -> new -> project -> Visual C++ exists something like a "managed testproject":
However when I create such a project I cannot manage it to add references e.g. to "MyClass.h" and to compile. And I cannot find a simple tutorial for that.
Can anyone help me by showing how to set up a simple C++ Unit Test with Visual Studio 2012?
To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).
The most scalable way to write unit tests in C is using a unit testing framework, such as: CppUTest. Unity. Google Test.
You have two choices for C++ unit tests Manage Test Project and Native Unit Test Project. You should select the native one, and then just add the includes you want and write the tests.
Here is a dummy example where I include a "foo.h" header, instantiate a foo
and call one of its methods.
#include "stdafx.h"
#include "..\foo.h" // <- my header
#include "CppUnitTest.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
foo f;
Assert::AreEqual(f.run(), true);
}
};
}
See Unit testing existing C++ applications with Test Explorer for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With