开发者

iPhone SenTestingKit failing to find AppDelegate in UnitTestBundle target

I'm trying to set up my unit testing for an iPhone application using XCode 3.2.3.

I followed the steps in http://developer.apple.com/iphone/library/documentation/xcode/conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html

As closely as I could, but I am getting this error message upon trying to build: "((yourApplicationDelegate) != 开发者_如何学Pythonnil)" should be true. UIApplication failed to find the AppDelegate

(this being the default trivial test for USE APPLICATION UNIT TEST is true)

I am building my app test target, as is discussed in the documentation, and get this error.

Do I need to ensure all my non-test case source is in my test bundle?

confused

--

I included the source files into my project and it compiles fine, but it still suffers the same unit test error:

"((yourApplicationDelegate) != nil)" should be true. UIApplication failed to find the AppDelegate

The original code is the same as the template code:

-(void) testAppDelegate {

    id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];
    STAssertNotNil(yourApplicationDelegate, @"UIApplication failed to find the AppDelegate");
}


Make sure that BUNDLE_LOADER and TEST_HOST build settings for the unit test bundle are specified.

BUNDLE_LOADER = $(BUILT_PRODUCTS_DIR)/YourApp.app/YourApp
TEST_HOST = $(BUNDLE_LOADER)

Furthermore, In Xcode4, many of steps described in the Apple's guide are not needed (e.g. duplicating app target). I recommend that creating new project including unit test and look around.


This is for the OP, in case the problem persisted and is still relevant, and for the forum browsers:

I, too, followed the gudielines in the iOS Development guide on Unit and Application testing. I, too, when following the Application testing guide, got a problem as per:

Test Suite 'FirstSuite' started at 2010-12-08 21:30:33 GMT 0000
Test Case '-[FirstSuite testAppDelegate]' started.
/Users/TomCruise/Documents/iPhoneDevelopment/PickerLeak/FirstSuite.m:22: error:-[FirstSuite testAppDelegate] : "((app_delegate) != nil)" should be true. Cannot find the application delegate.
Test Case '-[FirstSuite testAppDelegate]' failed (0.000 seconds).

I.e., the application delegate was not found as expected.

THE PROBLEM WAS that when I thought I followed the guidelines, I did not. Apparently the Application testing runs only on Device. So I switched from Simulator to Device (for AppTesting target), connected my iPhone, and then did Build + Run (cmd+return/enter). The application installed itself, and a few seconds later exited with return code 1 (which I guess signifies a faulty return code).

After the app had quit, I did shift + cmd + R, (uparrow+cmd+R) to get the log prompt, and could read the following:

2010-12-08 22:59:59.163 PickerLeak[5356:307] -[UIPickerView setFrame:]: invalid height value 200.0 pinned to 180.0 
Test Suite 'All tests' started at 2010-12-08 22:00:00 GMT 0000
Test Suite '/var/mobile/Applications/{number}/PickerLeak.app/PickerLeakTests.octest(Tests)' started at 2010-12-08 22:00:00 GMT 0000
Test Suite 'FirstSuite' started at 2010-12-08 22:00:00 GMT 0000
**Test Case '-[FirstSuite testAppDelegate]' started.
Test Case '-[FirstSuite testAppDelegate]' passed (0.001 seconds).**
Test Case '-[FirstSuite testFail]' started.
/Users/TomCruise/Documents/iPhoneDevelopment/PickerLeak/FirstSuite.m:17: error: -[FirstSuite testFail] : Must... fail.
Test Case '-[FirstSuite testFail]' failed (0.003 seconds).
Test Suite 'FirstSuite' finished at 2010-12-08 22:00:00 GMT 0000.
Executed 2 tests, with 1 failure (0 unexpected) in 0.004 (0.008) seconds

So... Hooray! :)

Godspeed, developers.


I've falled twice on this. You need to setup BUNDLE_LOADER and TEST_HOST build settings to make it work. But it is not enough, you need to also set Bundle Loader and Test Host. Please check how to implement application tests in xcode4?, that answer worked perfectly fine for me.


I can't directly answer your question, because I also never got application tests to work with OCUnit. I understand a number of people use the Google Toolbox for Mac iPhone unit testing library or GHUnit to make this easier.

As the Blazing Cloud post linked above points out, OCUnit (and GTM/GHUnit) are more JUnit-style than Rspec-style. At Pivotal we use Rspec for nearly everything, and we wanted something similar for Objective C. So, we wrote Cedar, and we intentionally designed it to work with UIKit, run on iOS devices, etc. It's freely available and open source; if you have any questions about it you can email the discussion group: cedar-discuss@googlegroups.com.


According to Apple's documentation, there are 2 kind of unit tests.

  • logic tests
  • application tests

The application tests are working only on hardware device. If you're using simulator, it won't work.

See this: http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜