Questions tagged [microsoft-cpp-unit-test]

31 questions
7
votes
2 answers

C++ unit test testing, using template test class

I’m doing some C++ test driven development. I have a set of classes the do the same thing e.g. same input gives same output (or should, that’s what I’m try to test). I’m using Visual Studio 2012’s CppUnitTestFramework. I wanted to create a…
Dan H
  • 706
  • 1
  • 6
  • 15
6
votes
2 answers

How to call the Assert::ExpectException correctly?

I'm writing some unit tests using Microsoft's CppUnitTestFramework. I want to test, if the method I call throws the correct exception. My code is: TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces) { std::string input{…
5
votes
1 answer

Visual Studio 2015 does not discover unit tests: C++

I am working on a C++ project and I developed a few test cases. I was able to execute the test cases until suddenly all the test cases disappeared from the test explorer. I mean to say that test methods are not shown in test explorer even though the…
NJMR
  • 1,886
  • 1
  • 27
  • 46
4
votes
1 answer

Problem in writing "DivideByZero" Unit test case using CPPUnitTest in Visual Studio 2019 C++

Unit testing means writing code that verifies individual parts, or units, of an application or library. A unit is the smallest testable part of an application. Unit tests assess code in isolation. In C++ this means writing tests for methods or…
4
votes
1 answer

How to use Google Mock with CppUnitTestFramework

TL;DR: You can use GMock to add mocking capability to your Microsoft native c++ unit tests. See my answer below for details. I want to start adding mocks to my existing set of native unit tests. The tests are written using Microsoft's…
4
votes
3 answers

Parametrized Test method in Microsoft::VisualStudio::CppUnitTestFramework

I'm writing some test cases for my C++ project using Microsoft::VisualStudio::CppUnitTestFramework. Here I have a case where I have to run a same test case with different parameters. In Nunit Framework for CPP, I can achieve this by the following…
4
votes
1 answer

How to set Timeout in CppUnitTestFramework (C++) in Visual Studio?

How to Add Timeout for a test method in C++ in Microsoft unit testing using CppUnitTestFramework ? Most of the Solutions I found online are for CSharp projects where I can add lines like [TEST_METHOD,TIME_OUT(80)] or such ,but those are not working…
abhirulz
  • 87
  • 1
  • 2
  • 11
3
votes
1 answer

Way to print message to debug output with Visual Studio CppUnitTestFramework

Is there a way to print messages to output window with CppUnitTestFramework in Visual Studio. There is TRACE() function to display messages from program in the debugger Output window in MFC. I want to know whether that kind of function exists or not…
Hill
  • 3,391
  • 3
  • 24
  • 28
2
votes
0 answers

Assert.Inconclusive analogue for MS C++ unit testing framework or how to skip test on the run?

I want to be able to skip a current test from its body. Of course, I could simply do this: if (condition) return; But this will show the test as "passed". I want to keep the user informed that the test is neither passed nor failed if (condition)…
Anton Serov
  • 174
  • 2
  • 12
2
votes
1 answer

How to assert if two vectors are equal in CppUnitTest framework

I am trying to assert 2-D vectors as shown below TEST_METHOD(TestCase1) { std::vector arr{2}; int sum{ 2 }; std::vector> subsets; std::vector> expected{ {2} }; generate_subsets(subsets, arr,…
Debargha Roy
  • 2,320
  • 1
  • 15
  • 34
2
votes
1 answer

How to initialize test variables using Visual Studio CppUnitTestFramework

I'm writing a roboter controller class Controller in which I'm using a struct Axis for each of the 4 controllable motors. For each test I want to reset everything, so I created a pointer in the class which is changed to a new Controller before each…
JoschJava
  • 1,152
  • 12
  • 20
2
votes
0 answers

CppUnitTest stuck in runtime and pass with break point

I'm just starting to learn the CppUnitTest framework and I'm having the weirdest problem. When I'm running my code (see bellow) it just stuck forever, however - if I'm adding a breakpoint and running it as "step-by-step" the test finish successfully…
Yonatan Karp-Rudin
  • 1,056
  • 8
  • 24
2
votes
1 answer

Can't run tests in CppUnitTestFramework (VS2013)

On a separate perforce stream from the rest of my team, I can't run CppUnitTestFramework tests on a project, while the rest of the streams run the tests just fine. Here's a code snippet: TEST_CLASS(MyClass) { BEGIN_TEST_CLASS_ATTRIBUTE() …
1
vote
1 answer

CppUnitTestFramework: Variable value set in TEST_CLASS_INITIALIZE does not persist in TEST_METHOD

I have a std::string declared in my TEST_CLASS that should be initialized once for the class that is to be used in two other TEST_METHODs. However, when TEST_CLASS_INITIALIZE is called (which does run before any TEST_METHOD), projectDirectory is…
Dash
  • 306
  • 1
  • 3
  • 16
1
vote
1 answer

Inheritance with CppUnitTestFramework

I want to make global classes because I want to do the same initialize across my tests. I tried like that, I've mutiples errors like ambiguous access. Someone have an idea ? #include using namespace…
Cylexx
  • 346
  • 1
  • 10
1
2 3