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

  • SEARCH
  • Home
  • 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 8397585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:49:47+00:00 2026-06-09T20:49:47+00:00

I am trying to learn unit tests. Following is my first ever written unit

  • 0

I am trying to learn unit tests. Following is my first ever written unit test for comparing string returned from the server. I am sure it’s not perfect the way I handled the internet connection’s availability and nsnotification. Test testGetURLEncodedString always printed pass as there is no assert statement in it. I can’t put assert there as I have to compare the returned result from the server after response is received. Could anyone please suggest me to correct way of doing this please.

#import "MyAppTests.h"

@interface MyAppTests()
    @property(nonatomic) AppDelegate *delegate;
@end

@implementation MyAppTests

@synthesize delegate = _delegate;

- (void)setUp
{
    [super setUp];

    self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if(![self.delegate internetConnectionAvailable])
    {
      STFail(@"Internet is not reachable.");
      exit(-1);
    }
}

- (void)tearDown
{
    _delegate = nil;
     [super tearDown];
}

- (void)testDelegate
{
     STAssertNotNil(self.delegate, @"Cannot find the application delegate");
}

- (void)testGetURLEncodedString
{
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getURLEncodedStringSuccess:) name:@"getURLEncodedStringSuccess" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getURLEncodedStringFailed:) name:@"getURLEncodedStringFailed" object:nil];

    [self.delegate getURLEncodedString:@"Testing Text"];
}

-(void)getURLEncodedStringSuccess:(NSNotification *)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getURLEncodedStringSuccess" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getURLEncodedStringFailed" object:nil];

    STAssertTrue([[self.delegate getURLEncodedStringResponse] isEqualToString:@"Testing Text"], @"testGetURLEncodedString failed - did not receive expected response");
 }

-(void)getURLEncodedStringFailed:(NSNotification *)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getURLEncodedStringSuccess" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getURLEncodedStringFailed" object:nil];

    STFail(@"testGetURLEncodedString failed - server failed returning 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-06-09T20:49:48+00:00Added an answer on June 9, 2026 at 8:49 pm

    Automated tests that call a server and check the response are better called “acceptance tests” of the server. But they should be kept in a separate target from the an app’s unit test target, because unit tests need to be blazingly fast. And the main way to keep them fast is to avoid any real networking. And that’s getting a little advanced.

    Since you’re just getting started with OCUnit, I suggest you not start with acceptance tests, because they’re typically harder to write and provide less precise feedback. Instead, begin with the simplest tests which are tests of your model logic. My Xcode TDD 101 may be helpful for learning the mechanics of unit testing.

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

Sidebar

Related Questions

I'm currently trying to learn proper unit-test. So now I'm trying to write unit-tests
I was trying to learn unit test with PHP. I know it's a bit
I am trying to learn unit testing. I am trying to unit test some
I am trying to learn database unit testing from ndbunit tutorial. All is going
I am trying to learn the unit tests in Play scala, but I am
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to
I'm in the process of trying to 'learn more of' and 'learn lessons from'
I was trying learn lex and yacc using the oreilly book. I tried following
I am trying to learn about unit testing in Zend Framework. I have installed
I'm trying to learn dependency injection and have come across a problem, when unit

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.