How to test part of the code without creating a new project?



I am using visual studio and creating a nontrivial project. There are many files containing many functions. I want to write "test case" for different functions or group of functions if they call each other so I can double check if the functions are working correctly after modifcation and if the main program fails, I can track where exactly in the chain garbage is being generated.

I have created different visual studio projects and copied code to test it, but this is not doable since I can't be copying code all the time to new project created just for testing code from another project. What advice do you have?

You could use a testing framework. For instance, doctest https://github.com/onqtam/doctest
you should not copy code. You can make a new project that uses the same source files and path it up to work.

Another approach is to build library object files of logical chunks of a large project. The test code is then testing the library, so you know it was compiled the same way as the master, and is identical to the master, etc.

You can also set up debugging in your main project, to have it enter a special debug or self-test mode by activating some hidden option; a commandline executable parameter for example can do this, if argv[1] == specialmagiccode, rundebugfunction() ... etc.

Topic archived. No new replies allowed.