I’m trying to implement unit testing for my code and I’m having a hard time doing it.
Ideally I would like to test some classes not only for good functionality but also for proper memory allocation/deallocation. I wonder if this check can be done using a unit testing framework. I am using Visual Assert btw. I would love to see some sample code , if possible !
You can use the debug functionality right into dev studio to perform leak checking – as long as your unit tests’ run using the debug c-runtime.
A simple example would look something like this:
And to use it in a unit test:
Some unit test frameworks make their own allocations – Google’s for example allocates blocks when a unit test fails, so any test block that has a fail for any other reason always also has a false positive “leak”.