c++ - UnitTest++ command line arguments -


i want use command line argument in 1 of tests. couldn't find example of on web.

test(sometest) {     std::string file("this command line argument");     check(something); }  int main(int argc, char** argv) {     return unittest::runalltests(); } 

any ideas?

answer

there's no real reason test command-line arguments directly. instead, write unit tests check behavior of code (functions , classes) given different arguments. once satisfied code working under unit test, plug main , should work there, well.

clarification

imagine have unit test on argument std::string constructor.

test(sometest) {     std::string file("this command line argument");     check(something); } 

then plug main.

int main(int argc, char** argv) {     std::string file(argv[1]);      // stuff....      return 0; } 

because nothing should happen command-line argument before passed constructor, you have tested already. if, on other hand, main mess, suggest refactoring first.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -