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
Post a Comment