An-abstract-image-created-using-street-lights-and-scaled.jpg by .

Page3 Html 83266728405490396

 

CppUnit FAQ

  • How do I verify that my private/protected methods are successful?

Since you don’t have access to your private/protected methods from the CppUnit module you can’t get any information contained in them.  You can, however, test the functionality of these methods by making sure you construct your test data properly.  It may take a little more work but you can always set your test up such that all possible paths through these methods are exercised.

  • Writing CppUnit tests takes a long time…why would I ever want to do this?

Several reasons, dammitt.

  • Do I write my tests before writing actual code?

Yes.  Sort of.  You should always identify all of your test cases and begin by writing very simple CppUnit tests for each of them.  But at this stage you’re not going to know exactly what each test will require and what needs to be validated.  As you begin coding and figure things out, go back to your test and update as necessary.

  • How many test cases should I have?

Four.  Ok, that’s probably not always the case, but who knows?  You should have as many test cases as are appropriate.  It’s up to you.  You might want to have one test case for each public method in your module (as well as the associated error conditions).  Maybe you want to break your tests down to a very fine level and have a single test for each “assertable” event.  Or maybe you want one huge test case with 68 asserts.

The bottom line is that it’s up to you to decide how to break up your test cases.

  • My program doesn’t output any data, how do I validate that it’s working?

While it’s possible to write a program that does absolutely nothing, yours is probably doing SOMETHING.  The trick with testing some modules using CppUnit is finding out what that something is.  It’s very easy to validate modules that result in data being written to a database, or something being written to the screen.  For others, the events you validate might not be so apparent.  i.e.  How would you validate the following code that prints a statement to the screen?:

public void TestMe () {

cout <<“I’m on the screen”;

}

Normally you would run that piece of code and look at the screen to verify that it’s working.  Unfortunately, that’s not going to work with CppUnit.  So how would you test this?  I DON’T KNOW.

  • The class I’m testing uses command-line parameters – how can I simulate this using CppUnit?

Luckily Allen Adams already thought of this.  CppUnit automatically loads AppArgs with any CL parameters passed to it.

  • How do I test error conditions?
  • Who do I contact if I need help?
  • Is there a basic example out there that I can pirate?
  • Can I run selected CppUnit tests as part of my nightly build?
  • What should I put in the “setup”/”teardown” methods?

 

You may also like...