Frage

I'm new to CppUnit testing and I have a basic set of questions.

So, CppUnit tests need a main function to run. However, I want this main to be separate from the main of the project I want to test. So, since you can't have 2 main functions in one project I created a subproject (I'm using Qt by the way) which will house all of my test classes. However, this seems to be causing its own set of issues since in Qt I can specify which subproject I want to run. This may mean I can't make them subprojects and keep them separate.

I'm used to JUnit, where there is a 1-to-1 pairing of classes to test classes and when I want to run a test case on a class, I would right-click it and run. No main function needed.

I guess I'm looking for an explanation of how to test a preexisting, mature project that doesn't currently have testing. Everything I find assumes you're developing parallel the project and its testing.

Thank you!

War es hilfreich?

Lösung

CPPUnit is flexible enough that you can test functional areas of most of your code with ease: what I call consumption side and implementation side.

Starting with a large preexisting library it is generally a good idea to setup external 'consumption' test cases that make heavy use of Fixtures in cppunit. To this you're essentially testing the outside-looking-in functionality of your object classes. You'll setup objects you're familiar with in the fixtures and write test cases for them. As you have the time, add more and more inside test cases specific to the internals of each class and pairing as they relate to classes that interact. eventually all new code you write will have test cases integrated or paired with them (literally hundreds or thousands as time progresses).

I'll be the first to tell you cppunit is no silver bullet, and is nowhere near as flexible as junit (the simple lack of reflection native to the language is a huge reason why). But it is still definitely worth spending the time.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top