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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:42:10+00:00 2026-06-17T13:42:10+00:00

I want to write unit tests using Apple’s default SenTestingKit for the below method:

  • 0

I want to write unit tests using Apple’s default SenTestingKit for the below method:

- (NSDictionary*)getValueTags {
    return _tags;
}

- (NSString*)getFlag {
    NSString* jo = @"";
    for (NSString* key in _tags) {
        jo = [jo stringByAppendingFormat:@"%@=\"%@\"&", key, [_tags objectForKey:key]];
    }
    if ([jo length] > 0) {
        jo = [jo substringToIndex:[jo length] - 1];
    }
    return jo;
}

I used default SenTesting

    - (void)setUp
    {
        [super setUp];

        // Set-up code here.
    }

    - (void)tearDown
    {
        // Tear-down code here.

        [super tearDown];
    }

-(void)testValueTags{

}

-(void)testGetFlag{

}

I am new to writing TestCases, I need some guideline for sample methods to write test cases

  • 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-17T13:42:12+00:00Added an answer on June 17, 2026 at 1:42 pm

    A test case has four distinct phases:

    1. set up
    2. exercise
    3. verify
    4. tear down

    Some of these phases can be empty. For example, most tear down happens automatically if you use ARC.

    When you’re starting, don’t put anything into the setUp or tearDown methods. Just write a single unit test. Here’s a worked example. (I’m going to change the names, because Objective-C idiom is not to use the word “get”. So instead of getFlag let’s just call it flag.) I’m going to call the class `Example, and I’ll use ARC. And I use the abbreviation “sut” for “system under test”.

    - (void)testFlagGivenOneEntry
    {
        // set up
        Example *sut = [[Example alloc] init];
        [sut setTags:@{ @"key1" : @"value1" }];
    
        // execute & verify
        STAssertEqualObjects([sut flag], @"key1=\"value1\"", nil);
    }
    

    That’s one test. Let’s add another.

    - (void)testFlagGivenTwoEntries
    {
        // set up
        Example *sut = [[Example alloc] init];
        [sut setTags:@{ @"key1" : @"value1",
                        @"key2" : @"value2" }];
    
        // execute & verify
        STAssertEqualObjects([sut flag], @"key1=\"value1\"&key2=\"value2\"", nil);
    }
    

    At this point, we have duplicate code: the creation of the sut. Now we can promote the variable up to an instance variable of the class. Then we create it in setUp and destroy it in tearDown:

    @interface ExampleTest : SenTestCase
    @end
    
    @implementation ExampleTest
    {
        Example *sut;
    }
    
    - (void)setUp
    {
        [super setUp];
        sut = [[Example alloc] init];
    }
    
    - (void)tearDown
    {
        sut = nil;
        [super tearDown];
    }
    
    - (void)testFlagGivenOneEntry
    {
        [sut setTags:@{ @"key1" : @"value1" }];
        STAssertEqualObjects([sut flag], @"key1=\"value1\"", nil);
    }
    
    - (void)testFlagGivenTwoEntries
    {
        [sut setTags:@{ @"key1" : @"value1",
                        @"key2" : @"value2" }];
        STAssertEqualObjects([sut flag], @"key1=\"value1\"&key2=\"value2\"", nil);
    }
    
    @end
    

    For a more involved example, see Objective-C TDD: How to Get Started.

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

Sidebar

Related Questions

I want to write some unit tests for my COM object using googletest. Unfortunately
I do write unit tests while writing APIs and core functionalities. But I want
I'm writing some unit tests in UnitTest++ and want to write a bunch of
I'm attempting to write some unit tests using EasyMock and TestNG and have run
It has been decided to write some unit tests using moq etc..It's lots of
I have a singleton class with private constructor and want to write unit tests
I want to write some unit tests for an interceptor that intercepts the Loggable
I want to write unit tests for a web service. I create my test
I want to write unit tests for a subroutine in perl. The subroutine is
I want to write unit tests for a module file I created and put

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.