Closed louiske0911 closed 5 years ago
@ekeroc, as mentioned, use the language features. Keep a function pointer and store the original function before assigning the custom delegate.
Feel free to ask for more information or, if you've found a solution, post an example.
@wulfgarpro could you elaborate please? I am having the same issue. I am trying to fake functionA, which lives in .h file which I have included in my .cpp unit test file. I am trying to fake the function with FAKE_VALUE_FUNC(bool, functionA); but I get the errors "one or more multiply defined symbols found" and "funcationA already defined in .h". What can I do?
Thanks
Edit: My production code was all part of one big project within Visual Studio. I decided to split the large project up into smaller components so I could unit test each component individually. This solved my problem as I could then fake off the dependencies for the unit I was testing without having multiple defines of the function.
@KasperZK can you provide a cut down example?
@wulfgarpro sure
#include "pch.h"
#include "CppUnitTest.h"
#include "..\fff.h"
extern "C"
{
#include "ioDigitalInput.h"
}
DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC(bool, ioFunc);
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTestfff
{
TEST_CLASS(UnitTestfff)
{
public:
TEST_METHOD(TestMethod1)
{
}
};
}
ioFunc is implemented in ioDigitalInput.c
It should probably also be said that I am building the production code from another project within the same solution as the test project is placed in VS2019. The library files from the production code are then used in the test project.
Hi, could I still use the original function after I faked this function in my unit test?