I'm trying to add unit tests and mocks to a legacy project. As part of this I partially mocked one of the classes, mocking just the methods that I need in the class I'm currently testing. I then pass this mock in to the class for dependency injection and delete it in the destructor, however when I run the test it complains:
ERROR: this mock object (used in test xxxx) should be deleted but never is. Its address is @0000000004208AD0.
ERROR: 1 leaked mock object found at program exit.
When debugging through the code I can see that delete is being called on the mock object in the destructor, but it's still complaining. If I call delete again at the end of the test I get an SEH exception thrown because I'm trying to delete memory that's already been de-allocated, but if I comment out the delete in the destructor then it works (but this would obviously cause a memory leak)