Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

lzyTest/XCParameterizedTestCase

Open more actions menu
 
 

Repository files navigation

XCParameterizedTestCase

Twitter License CocoaPods Build Status

Parameterized implementation of XCTestCase.

Intro

The idea behind parameterized test case is to pass a collection of <TestCaseData> objects instead of defining multiple test methods, e.g.

instead of this:

- (void)test_outputForInteger_when_03_returns_fizz {
	NSInteger input = 3;
    assertThat([FizzBuzz outputForInteger:input], equalTo(@"Fizz"));
}

- (void)test_outputForInteger_when_05_returns_buzz {
    NSInteger input = 5;
    assertThat([FizzBuzz outputForInteger:input], equalTo(@"Buzz"));
}

you do this:

+ (NSArray *)testCaseData {
    return @[
             [XCTestCaseData createWithInputValue:@3 withExpectedValue:@"Fizz"],
             [XCTestCaseData createWithInputValue:@5 withExpectedValue:@"Buzz"],
             ];
}

License

Source code of this project is available under the standard MIT license. Please see the license file.

Mechanics

XCParameterizedTestCase is a subclass of XCTestCase. It contains a single test method which is executed multiple times, depending on the number of test case data supplied. A test case data, represented by a class that conforms to <TestCaseData> protocol, holds input value and expected value.

For each test case data passed, XCParameterizedTestCase injects new XCTestCase to XCTestSuite with a pair of input and expected values specified by a test case data.

Example output of FizzBuzz parameterized test case with 5 test case data:

License MIT

Installation

XCParameterizedTestCase is available through CocoaPods.

In your Podfile simply add the following code:

target :YourTestTarget, :exclusive => true do
    pod 'XCParameterizedTestCase',	'>= 0.9.0'
end

Usage

Step 1 - Make your test a subclass of XCParameterizedTestCase

@interface FizzBuzzTests : XCParameterizedTestCase

Step 2 - Override (NSArray *)testCaseData method and define your test case data.

+ (NSArray *)testCaseData {
    return @[
             [XCTestCaseData createWithInputValue:@1 withExpectedValue:@"1"],
             [XCTestCaseData createWithInputValue:@3 withExpectedValue:@"Fizz"],
             [XCTestCaseData createWithInputValue:@5 withExpectedValue:@"Buzz"],
             [XCTestCaseData createWithInputValue:@6 withExpectedValue:@"Fizz"],
             [XCTestCaseData createWithInputValue:@15 withExpectedValue:@"FizzBuzz"]
             ];
}

Step 3 - Implement your test using self.input and self.expected properties.

- (void)test_fizbuzz {
    id result = [FizzBuzz outputForInteger:[self.input integerValue]];
    XCTAssertEqualObjects(self.expected, result, @"");
}

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b new-feature).
  3. Commit your changes (git commit -am 'Added new-feature').
  4. Push to the branch (git push origin new-feature).
  5. Create new Pull Request.

About

Parameterized implementation of XCTestCase.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Objective-C 94.0%
  • Ruby 3.7%
  • Makefile 2.3%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.