Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7078083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:30:10+00:00 2026-05-28T06:30:10+00:00

I have the following Objective C test code in a SenTestCase class. I get

  • 0

I have the following Objective C test code in a SenTestCase class. I get no errors, but the httpReceiveDataFinished method never gets called. Is this because the test is ended before the delegate has a chance to process the http method?

If that is the case how can I spin off a thread (or something similar) to make the test wait for a few seconds?

Thanks a million for any help. I have programmed Java for years, but Objective-C only a few days.

- (void)testExample
{
    HttpClient *client = [[HttpClient alloc] init];
    client.method = METHOD_GET;
    client.followRedirects = YES;
    [client processRequest:@"http://google.com" delegate:self];
    NSLog(@"Test Over");
}

-(void) httpReceiveError:(NSError*)error {
    NSLog(@"***\n%@\n***",[error description]);
}

- (void) httpReceiveDataChunk:(NSData *)data {
    [self.httpResponseData appendData:data];
}

-(void) httpReceiveDataFinished {
    NSString *result = [[NSString alloc] 
        initWithData:self.httpResponseData 
        encoding:NSUTF8StringEncoding];
    NSLog(@"***\nRESULT: %@ \n***",result);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:30:10+00:00Added an answer on May 28, 2026 at 6:30 am

    First: Stanislav’s link is excellent.
    For myself, I needed something that was more flexible (run for long durations) but would also pass the test immediately on success. (Large file downloads and the like.)

    Here’s my utility function:

    -(BOOL)runLooperDooper:(NSTimeInterval)timeoutInSeconds 
          optionalTestName:(NSString *)testName 
    {
        NSDate* giveUpDate = [NSDate dateWithTimeIntervalSinceNow:timeoutInSeconds];
        // loop until the operation completes and sets stopRunLoop = TRUE
        // or until the timeout has expired
    
        while (!stopRunLoop && [giveUpDate timeIntervalSinceNow] > 0) 
        {
            // run the current run loop for 1.0 second(s) to give the operation code a chance to work
            NSDate *stopDate = [NSDate dateWithTimeIntervalSinceNow:1.0];
            [[NSRunLoop currentRunLoop] runUntilDate:stopDate];
        }
    
        STAssertTrue(stopRunLoop, 
                     @"%@ failed to finish before runloop expired after %f seconds", testName, timeoutInSeconds);
        return stopRunLoop;
    }
    

    Declare stopRunLoop as an ivar in your tester-class. Make sure to reset stopRunLoop to FALSE in your setUp function, and call this function prior to calling your [client processRequest:@"http://google.com" delegate:self]; Then, in your event handlers, set stopRunLoop to TRUE.

    By passing it a testName, you can reuse it for multiple tests and get some meaningful error messages.

    Edit: 99% sure I based the above code off of another StackOverflow post that I can’t find at the moment, or I’d link it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code snippet: class Test { public int Length{ get; set; }
I have the following objective C class. It is to store information on a
Say I have the following Objective-C class: @interface Foo { int someNumber; NSString *someString;
While attempting my first sub-class in Objective-C I have come across the following warning
I have written some Objective-C test cases. A typical looks the following: - (void)
I have the following code in Objective-C for the iPhone, using NSDateFormatter: NSDate *today
I have a class called Location with the following automatically generated declaration, #import <Foundation/Foundation.h>
I have the following Objective-c Function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger
I have the following class hierachy: @interface Message : NSObject {} @end @implementation Message
I have the following Objective-C function: +(NSString *)stringToSha1:(NSString *)str{ NSMutableData *dataToHash = [[NSMutableData alloc]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.