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 9168739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:41:52+00:00 2026-06-17T15:41:52+00:00

As I heard before and recently learned in Jon Reid’s very good screencast ,

  • 0

As I heard before and recently learned in Jon Reid’s very good screencast, some init methods or in iOS applications, the viewDidLoad methods tend to get bigger and bigger. I tried to refactor this method:

- (void)viewDidLoad {
    // 10+ lines of setting default property

    // 20+ lines of setting up the navigation bar

    // 20+ lines of resetting the view hierarchy
}

This was replaced by a very nice and short method that contains calls to other methods with speaking names:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setDefaultResourceNames];
    [self setupRightBarButtonItems];
    [self restoreNavigationControllerHierarchy];

    [[NSNotificationCenter defaultCenter] addObserver: (...)];

}

Now those three methods are now being unit tested, which is much better than before. Now my question is, should the viewDidLoad method be tested as well?

To do this, I made a partial mock out of my class under test and wrote the following test:

- (void)testViewDidLoadShouldInstantiateControllerCorrectly {
    NewsItemDetailsViewController *sut = [[NewsItemDetailsViewController alloc] init];
    id mockSut = [OCMockObject partialMockForObject:sut];
    [[mockSut expect] setDefaultResourceNames];
    [[mockSut expect] setupRightBarButtonItems];
    [[mockSut expect] restoreNavigationControllerHierarchy];

    [mockSut viewDidLoad];

    [mockSut verify];
}

Is this any good? This seems to be largely coupled to actual source code and method execution rather than effects caused by calling the method (which is actually what unit testing is about, as far as I learned). But the effects of calling the method are actually covered in the three unit tests, testing the sub-methods.

Is it good to have this test or is it unnecessary when all other calls are already under test?

  • 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-17T15:41:53+00:00Added an answer on June 17, 2026 at 3:41 pm

    This is a perfectly reasonable approach. You want to test two types of things: 1) things you don’t want to break, and 2) things you want to document. If this approach fits either or both of those criteria for you it’s fine.

    I think the main drawback of tests like this is that they can add a lot of coding overhead to something that is self-evident. View setup code is often very readable–you can scan through it and understand what’s going on, so the tests don’t add much documentation value. And if the view is one you use every time you use the app, it may be immediately clear when you do QA if any of the view setup is broken, so the tests don’t add much defensive coding value.

    In the end, you’re the one who will maintain this code and be responsible for fixing it when it breaks, so it’s up to you to determine whether the testing effort now outweighs the risks later.

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

Sidebar

Related Questions

I've heard before that modules are just classes too. I have a few situations,
Ive never heard of this before, and I have been coding in PHP for
I had never heard of persistent connections before, and I don't understand the advantages.
I am referred to Hudson today. I have heard about continuous integration before, but
Before I start this may be hard for some people to understand. Sorry. I
I recently changed some of my pages to be displayed via ajax and I
I've recently started getting into data analysis and I've learned quite a bit over
I have used AspectJ before for Java, and I recently have thought about checking
I recently noticed that some (not all) of my javascript and jQuery scripts wouldn't
Recently I've been doing some benchmarking of the write performance of my company's database

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.