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: Sat, 5 Nov 2005 22:38:16 -0700
Chris Hanson wrote on Saturday, November 5, 2005:
>On Nov 5, 2005, at 4:23 PM, James Bucanek wrote:
>
>> The documentation seems to hint that a "dependent" unit test can be
>> configured to load the actual application executable as if it were
>> a dynamic library, link the unit tests to that binary code, and
>> execute the tests. This is referred to as "bundle injection."
>
>Whether tests are dependent is orthogonal to whether bundle injection
>takes place. Dependent tests are tests that are kept separate from
>the code under test, whether it's an application, tool, or
>framework. Bundle injection takes place when testing applications or
>tools.
>
>Also, bundle injection doesn't quite work the way you describe. It
>launches the application (or other executable) in a special
>environment and injects the unit test bundle into it dynamically,
>which in turn executes the tests.
I'm starting to figure that out. I also suspect this is the root of my problem.
>> However, the only example of doing this demonstrates using a
>> bundled app with a TEST_HOST of $(BUILT_PRODUCTS_DIR)/MyApp.app/
>> Contents/MacOS/MyApp. I've tried to set the TEST_HOST to my command-
>> line executable at $(BUILT_PRODUCTS_DIR)/MyTool without success.
>
>As far as I know, this should work. What kind of failure are you
>seeing? Did you also set the BUNDLE_LOADER for your test bundle to
>the path to MyTool?
Yes, I've set BUNDLE_LOADER and TEST_HOST to the same value.
>> Does this technique only work for bundled apps? Is there some way
>> of doing this for other kinds of executable products, or must I
>> compile the code seperately in the unit test target? I can find no
>> documentation for otest or the RunUnitTest scripts that explain how
>> they load and execute their tests. I know it's supposed to "just
>> work," but in this case I'm afraid I need to know.
>
>There are man pages for otest and RunUnitTests.
Yes they do, and I read them. But they don't really say anything beyond what the basic Unit Testing docs do. I was trying to find out *how* the otest tool did it's magic, not just what parameters to pass.
>Setting your
>TEST_HOST to an executable should work, and a more detailed
>description of the failure you're seeing will help diagnose it.
OK, what' I've done is create two projects (these are just demonstration projects, so this is no big deal). I've got an Objective-C command-line tool and a Cocoa app. Both programs test prime number (whoo hoo!).
I created a Unit Test target on both. Made both dependent on the application/tool target and set the TEST_HOST and BUNDLE_LOADER build setting in the unit test target.
The unit tests on the Cocoa app works just fine. Here's some of the build log:
/bin/sh -c
//Users/james/Desktop/PrimesObjCApp/build/PrimesObjCApp.build/Debug/
/PrimesAppUnitTests.build/Script-1A249D2E091DC3E600B763AB.sh
2005-11-05 22:06:34.660 PrimesObjCApp[5798] +[NSATSGlyphGenerator initialize]
invocation. The class is deprecated. Test Suite 'All tests' started at
2005-11-05 22:06:34 -0700 Test Suite
'/System/Library/Frameworks/SenTestingKit.framework(Tests)' started at
2005-11-05 22:06:34 -0700 Test Suite 'SenInterfaceTestCase' started at
2005-11-05 22:06:34 -0700 Test Suite 'SenInterfaceTestCase' finished at
2005-11-05 22:06:34 -0700. Passed 0 tests, with 0 failures (0 unexpected) in
0.000 (0.000) seconds
Test Suite '/System/Library/Frameworks/SenTestingKit.framework(Tests)' finished
at 2005-11-05 22:06:34 -0700. Passed 0 tests, with 0 failures (0 unexpected) in
0.000 (0.000) seconds
Test Suite
'/Users/james/Desktop/PrimesObjCApp/build/Debug/PrimesAppUnitTests.octest(Tests
)' started at 2005-11-05 22:06:34 -0700 Test Suite 'SieveOfEratosthenesTests'
started at 2005-11-05 22:06:34 -0700 Test Case '-[SieveOfEratosthenesTests
testInvalidNumbers]' passed (0.000 seconds). Test Case
'-[SieveOfEratosthenesTests testMapEdges]' passed (0.000 seconds). Test Case
'-[SieveOfEratosthenesTests testNonPrimes]' passed (0.000 seconds). Test Case
'-[SieveOfEratosthenesTests testPrimes]' passed (0.296 seconds). Test Suite
'SieveOfEratosthenesTests' finished at 2005-11-05 22:06:35 -0700. Passed 4
tests, with 0 failures (0 unexpected) in 0.297 (0.362) seconds
Test Suite
'/Users/james/Desktop/PrimesObjCApp/build/Debug/PrimesAppUnitTests.octest(Tests
)' finished at 2005-11-05 22:06:35 -0700. Passed 4 tests, with 0 failures (0
unexpected) in 0.297 (0.362) seconds
Test Suite 'All tests' finished at 2005-11-05 22:06:35 -0700. Passed 4 tests,
with 0 failures (0 unexpected) in 0.297 (0.363) seconds
My command-line tool, however, still doesn't run any tests. When I build it (the unit test target), I get the following:
/bin/sh -c
//Users/james/Desktop/PrimesObjC/build/PrimesObjC.build/Release/
/PrimesToolTest.build/Script-1A249CB5091D75C300B763AB.sh
2005-11-05 22:05:36.764 PrimesObjC[5740] CFLog (21): Cannot find executable for
CFBundle 0x302ee0
</Users/james/Desktop/PrimesObjC/build/Release/PrimesToolTest.octest> (not
loaded) DevToolsBundleInjection: Error loading bundle
'/Users/james/Desktop/PrimesObjC/build/Release/PrimesToolTest.octest'
2005-11-05 22:05:37.294 PrimesObjC[5740] There are 11301 prime numbers between
2 and 120000, inclusive
/Developer/Tools/RunUnitTests: line 182: 5740 Trace/BPT trap
/"${TEST_HOST}" ${TEST_HOST_FLAGS}
What I get are a "Cannot find executable for CFBundle" error, then an "Error loading bundle". What happens next is that the command line tool runs and exits (that's the "There are 11301 prime..." message). Finally, the RunUnitTests script dies.
I see that otest/RunUnitTests is launching the application, then trying to intercept something that will let it run the tests. However, my command-line tool just runs main() and exits. I suspect that otest doesn't have anything to sink its claws into. Or, maybe I've got some magic linker setting that's wrong. If I knew *how* otest injects the tests into the application it launches, then maybe I'd have a clue as to what needs to be changed to let otest work its mojo.
Thanks in advance for any insight you might have.
James
--
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