Re: otest -- only useful for bundles?
Re: otest -- only useful for bundles?
- Subject: Re: otest -- only useful for bundles?
- From: Chris Hanson <email@hidden>
- Date: Mon, 21 Nov 2005 19:04:29 -0800
On Nov 7, 2005, at 10:57 AM, James Bucanek wrote:
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)?
This is the correct way of running tests in a C++ tool or application
that doesn't have any sort of run loop or other mechanism that can be
hooked into from within a test bundle.
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.
The Carbon application example in the Unit Testing Guide is correct,
though as you've discovered you also have to turn off "Symbols Hidden
by Default" for the Debug configuration of the application target in
order to be able to link against the application's classes from your
unit test bundle.
All of the code in the Carbon application example that sets up a
timer is intended to be part of the test bundle, not the
application. Thus if no test bundle is injected into the
application, the application will be have normally. If a test bundle
is injected into the application, the application will quit after the
tests in the test bundle are run.
-- Chris
_______________________________________________
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