how to structure tests properly

Added by unknown unknown almost 6 years ago

hi,

after reading the wiki i have still open questions how to stucture my test code properly.

Lets assume the following:

I have given two classes (which need to be tested)
  • MyClass01 (implemented in the two files MyClass01.h and MyClass01.cpp)

this class has two methods which i want to test: return1() and return2()

  • MyClass02 (implemented in the two files MyClass02.h and MyClass02.cpp)

this class also has two methods which i want to test: returnA() and returnB()

Now i want my tests to be structured like the following:

MyClass01Test (This shall be a first TestSuite)

return01Test (This shall be a test of the first TestSuite)

return02Test (This shall be a test of the first TestSuite)

MyClass02Test (This shall be a second TestSuite)

returnATest (This shall be a test of the second TestSuite)

returnBTest (This shall be a test of the second TestSuite)

And i want my Code to bestructured hierachically.
This means:

  • in my test-main-file i only want to specify which TestSuits to use.
  • in my TestSuit-Files i want to specify the Tests which belong to the Suite.

The Wiki didn't help me out with this very well, because in the code examples only one Suite is used and all test methods are added in one big block and uses some mystic "functors" which only seem to be single test (instead of Suits) as well.

I'm thankfull for any answers.


Replies (4)

RE: how to structure tests properly - Added by Thomas Corbat almost 6 years ago

Hi

The plug-in should actually support you in creating suites. I suggest doing the following steps:

1. Create a new CUTE project (File -> New -> C++ Project -> CUTE -> CUTE Project). This will create your test-main-file. It contains an example test (thisIsATest) at beginning, which you can delete. Remove its registration as well.
2. Create a new suite file (File -> New -> Suite File). This will open a dialog asking for a name and also providing the option to link it to a runner. Check that box and select the runSuite function, which has been created automatically in step 1. (Beware: This option is only available if you have not deleted the cute::makeRunner call in the runSuite member function. This is working not quite properly as I have just seen, and will be improved.) The plug-in will then create the files for your suite and create a runner for it.

...
cute::suite C1 = make_suite_C1();
cute::makeRunner(lis)(C1, "C1");
...

3. Repeat step 2 for every suite you would like to have.
4. In the created suite source files (.cpp) you can implement your tests.

I hope this helps.

Regards
Thomas

RE: how to structure tests properly - Added by unknown unknown almost 6 years ago

Thanks, this helped me instantly. I didn't recognize the IDE option to create Suite Files before.

Found Bug: When in the "New CUTE Suite File" Dialog, after filling everything and clicking "OK" the dialog was not closed, but anything was created properly.

RE: how to structure tests properly - Added by Thomas Corbat almost 6 years ago

Glad I could help.

I actually never encountered the dialog staying open. What version of Eclipse and CDT are you using? Did anything appear in the error log.

RE: how to structure tests properly - Added by jetendar kumar about 5 years ago

To give the program something to do, replace the code in the main.c file with the following code to create a simple factorial calculator:
#include <stdio.h>
#include <stdlib.h>

long factorial(int arg) {
long result = 1;
int i;
for (i = 2; i <= arg; ++i) {
result *= i;
}
return result;
}

int main(int argc, char** argv) {
printf("Type an integer and press Enter to calculate the integer's factorial: \n");
int arg;
fflush(stdout);
scanf("%d", &arg);

printf("factorial(%d) = %ld\n", arg, factorial(arg));
return (EXIT_SUCCESS);
}

bulk sms in jaipur

(1-4/4)