Issues getting unit tests to run for statically linked program using Visual C++

John Eskew 41 Reputation points
2021-02-12T19:43:40.82+00:00

I'm attempting to create unit tests in my C++ project for the first time, but they simply won't run.

Attempted:

  • I've followed the instructions on the MS Docs site
  • Went through several answers from this SO question including:
    • Manually setting the Platform Target and the Test settings default processor architecture
    • Restarted VS (and my machine)
  • Changed several project properties in my "UnitTesting" project(nested inside of the main project(solution?) folder to match the "base project" (statically linked executable)

After changing some of the project properties to match the base the project(static linkage because base program is statically linked) and adding a reference to the "base project" from the "test project", I got rid of the errors, but the tests just don't run... A quick google search for the tests not running lead me to check the "tests" dropdown in the output window, but the error message there doesn't appear to provide me any meaningful context:

Tests not running

Here's the very simple test code I'm attempting to run:

#include "pch.h"  
#include "CppUnitTest.h"  
#include "../SysLatData.h"  
  
using namespace Microsoft::VisualStudio::CppUnitTestFramework;  
  
namespace UnitTesting  
{  
    TEST_CLASS(UnitTesting)  
    {  
    public:  
          
        TEST_METHOD(TestMethod1)  
        {  
            Assert::AreEqual(1, 1);  
        }  
    };  
}  

I guess these are my questions:

  • Am I missing something obvious to get this very simple test to work?
  • Should the "UnitTesting" project be built as an executable like the base project is?
  • Or should it be built as a static library that can be "built into" the base program at the "base project" build time?

Any help understanding this issue would be greatly appreciated.

Here's my source code: https://github.com/Skewjo/SysLat_Software/tree/CreateUnitTests

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,628 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
337 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114.5K Reputation points
    2021-02-12T19:58:34.89+00:00

    Try adding a new project to solution using the Add New Project wizard. Select “Native Unit Test Project” kind of project. Build the solution, then go menu, View, Test Manager. Check if the test was detected and can be executed.

    In Visual Studio 2019 this seems to work well.

    Do you have other projects in your solution? You can perform the experiments with a new solution too.