I want to do Unit Tests for a C project in Visul Studio 2017. It is a embedded project lib. I want make as few changes as possible to lib. Just compile c code in VS I have added some #ifdef WIN32. It ok for added some more.
Started with using Visual C++ Native Unit Test Project. But run in problems when wanted test private static functions from C files and inject values varibales in project.
- Include my embedded project as Static Library in to VS solution. (or should use Dynamic-Link library or something else?)
- Created Native Unit Test Project, and gave it the name UnitTest1.
- In UnitTest1 added this line as I understand it will include the my lib that want test.
#pragma comment(lib, "../Release/Embedded.lib")
In the embedded code header file I added this Macro to create lib that I will preform the test on.
#pragma once
#ifdef EXPORT_TEST_FUNCTIONS
#define UNITTEST_Embedded_EXPORT __declspec(dllexport)
#else
#define UNITTEST_Embedded_EXPORT
#endif
- inline UNITTEST_ZAP_EXPORT static bool isActiv(void);
- In the embedded C file, I added this line
#define EXPORT_TEST_FUNCTIONS
and this function:
UNITTEST_ZAP_EXPORT static bool isActiv(); { return false; }
- But when I build UnitTest1 get error LNK2001.
Very unsure how to proceed to make it work. Anyone who can guide me through my problem? I would like to be able to test all functions in C code. Hope it not hard understand what want get help with. I have only developed couple of years.