A cpputest starter project with instructions for Visual Studio
Create Your First Legacy C/C++ Test Project - Visual Studio
This describes how to integrate CppUTest based testing into your production code base using the Visual Studio environment. I'll assume you are using Visual Studio 2010 in the instructions, but there are other project files. As a reference, here are the other Visual Studio file extensions:
• VC6 file extensions (dsw, dsp)
• VS2008 file extensions (sln, vcproj)
• VS2010 file extensions (sln, vcxproj)
• VS2012 file extensions (sln, vcxproj)
• VS2019 file extensions (sln, vcxproj)
You should see these test results in the console window:
...................................
OK (1085 tests, 1037 ran, 2505 checks, 48 ignored, 0 filtered out, 331 ms)
Clone the starter-kit like this:
git clone https://github.com/jwgrenning/cpputest-starter-project-vs.git
You should see these test results in the console window:
..
OK (2 tests, 2 ran, 1 checks, 0 ignored, 0 filtered out, 0 ms)
Let's presume a directory structure like this:
ProductRepository
|-- include
|-- source
Copy the following files to your ProductRepository
• example-include/example.h
• example-include/io.h
• example-platform/io.c
• example-src/example.c
• tests/*.cpp
• vs-test-build/AllTests.vcxproj (VS2010)
• vs-test-build/ProductionCodeLib.vcxproj (VS2010)
• vs-test-build/TddC-StarterProject.dsw
• vs-test-build/TddC-StarterProject_VS2010.sln (VS2010)
ProductSourceRepository
|-- example-include
|-- example.h
|-- io.h
|-- example-platform
|-- io.c
|-- example-src
|-- example.c
|-- include
|-- source
|-- tests
|-- AllTests.cpp
|-- ExampleTest.cpp
|-- MyFirstTest.cpp
|-- vs-test-build
|-- AllTests.vcxproj
|-- ProductionCodeLib.vcxproj
|-- TddC-StarterProject.dsw
|-- TddC-StarterProject_VS2010.sln
You should see these test results in the console window:
..
OK (2 tests, 2 ran, 1 checks, 0 ignored, 0 filtered out, 2 ms)
Cause the test to fail. Open example.c, change the return result to 0. You should see:
.
tests\ExampleTest.cpp(21): error: Failure in TEST(Example, test1)
expected <1 0x1>
but was <0 0x0>
.
Errors (1 failures, 2 tests, 2 ran, 1 checks, 0 ignored, 0 filtered out, 14 ms)
You build fails because it cannot find CppUTest includes
Visual Studio Intellisense won't work properly / Code Navigation does not work