Re: otest -- only useful for bundles?
Re: otest -- only useful for bundles?
- Subject: Re: otest -- only useful for bundles?
- From: James Bucanek <email@hidden>
- Date: Mon, 7 Nov 2005 11:57:58 -0700
James Bucanek wrote on Sunday, November 6, 2005:
>-- Question #3 --
>
>Does the code I inserted into main() to run the test automatically turn off
>when the application is executed normally? Will it not spit out those annoying
>messages? How does my app know that tests should be run vs. when it should
>execute normally? Both the example code and the code I have above *alway* run
>the tests and exit. As its written now, my application won't ever run.
Slowly working my way through my own questions; it appears that the TestSuite and TestRun classes can be examined to determine if tests were defined/ran:
#ifdef UNIT_TEST_SUPPORT
TestRun run;
// Create a log for writing out test results
TestLog log(std::cerr);
run.addObserver(&log);
// Get all registered tests and run them.
TestSuite& allTests = TestSuite::allTests();
allTests.run(run);
// If the test suite ran test, then log the success or failure of those tests and exit.
// Otherwise, the application is not attached to a test harness and should be run normally.
if (run.runCount())
{
// Log a final message.
std::cerr << "Ran " << run.runCount() << " tests, " << run.failureCount() << " failed." << std::endl;
return (0);
}
#endif
Is this the correct way of handling tests in a C++ application (i.e. letting the application run normally iff TestSuite is empty)?
I notice that the example code for inserting this code into a Carbon application using a timer does not make this test. Looking at the code, it appears that it runs the tests then always calls QuitApplicationEventLoop(), which will forcibly terminate the application. Is the example code incorrect, or is there something I'm missing.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden