Upgrade to Pro — share decks privately, control downloads, hide ads and more …

My unit test environment for Objective-C

tokorom
December 21, 2013

My unit test environment for Objective-C

My unit test environment for Objective-C.
- The test for asynchronous processes
- Matcher
- CUI & Guard
- Coverage

tokorom

December 21, 2013
Tweet

More Decks by tokorom

Other Decks in Technology

Transcript

  1. ࠷ۙɺςετίʔυ؀ڥ ͲΜͳ͔Μ͡Ͱ͔͢ʁ ΅͘͸͜Μͳ͔Μ͡Ͱ͢ɻ ॴ ༑ଠ @tokorom iOS App Programer These

    are “not” confidential sessions—please “not” refrain from blogging, or taking pictures Yokohama iPhone Developers #14
  2. લఏ৚݅ • ඪ४ͷXCTestϑϨʔϜϫʔΫΛ࢖͏͜ͱ • Command + U Ͱςετ࣮ߦ & Xcode୯ମͰ΋

    ςετ݁Ռ͕֬ೝͰ͖Δ͜ͱ • ͜ͷൣғͰ֎෦ϥΠϒϥϦͷར༻Λڐ༰
  3. GHUnit - (void)testExample { [self prepare]; __block NSString *response =

    nil; [self requestGetAsyncronous:^(id res, NSError *error) { response = res; if (error) { [self notify:kGHUnitWaitStatusSuccess]; } else { [self notify:kGHUnitWaitStatusFailure]; } }]; [self waitForStatus:kGHUnitWaitStatusSuccess timeout:10.0]; XCTAssertEqualObjects(response, @“OK!”); }
  4. will @ Expecta - (void)testExample { __block NSString *response =

    nil; [self requestGetAsyncronous:^(id res, NSError *error) { response = res; }]; expect(response).will.equal(@“OK!”); }
  5. RubyMotion it 'should be xxx' do some_method_with_block {|some_data| @data =

    some_data resume } wait_max 1.0 do @data.should.equal ‘OK!’ end end
  6. ࡞ͬͨΑʂ - (void)testExample { __block NSString *response = nil; [self

    requestGetAsyncronous:^(id res, NSError *error) { response = res; RESUME; }]; WAIT; XCTAssertEqualObjects(response, @“OK!”); }
  7. XCTAsserts int i1 = 100; NSInteger i2 = 100; NSNumber

    *number = @100; NSString *string = @"OK"; ! XCTAssertEqual(i1, 100); XCTAssertEqual((int)i2, 100); XCTAssertEqualObjects(number, @100); XCTAssertEqualObjects(string, @"OK");
  8. OCHamcrest int i1 = 100; NSInteger i2 = 100; NSNumber

    *number = @100; NSString *string = @"OK"; assertThatInt(i1, equalToInt(100)); assertThatInteger(i2, equalToInteger(100)); assertThat(number, equalTo(@100)); assertThat(string, equalTo(@"OK"));
  9. Expecta int i1 = 100; NSInteger i2 = 100; NSNumber

    *number = @100; NSString *string = @"OK"; expect(i1).to.equal(100); expect(i2).to.equal(100); expect(number).to.equal(@100); expect(string).to.equal(@"OK");
  10. ςετࣦഊ࣌ͷΨΠυ • XCTAsserts •("OK") is not equal to ("NG") •(([number

    isKindOfClass:[NSString class]]) is true) failed • OCHamcrest •Expected "NG", but was "OK" •Expected an instance of NSString, but was __NSCFNumber instance <100> •Expecta •expected: NG, got: OK •expected: a kind of NSString, got: an instance of __NSCFNumber, which is not a kind of NSString
  11. Xcode 4.x xcodebuild \ -project $(PROJECT) \ -target $(TEST_TARGET) \

    -sdk iphonesimulator \ -configuration Debug \ TEST_AFTER_BUILD=YES \ TEST_HOST=
  12. Guard require 'guard/plugin' ! module ::Guard class InlineGuard < ::Guard::Plugin

    SCHEME = 'Tests' DESTINATION = 'platform=iOS Simulator,name=iPhone Retina (3.5-inch),OS=7.0' COMMAND = "xcodebuild test -scheme #{SCHEME} -destination '#{DESTINATION}'" def run_all system(COMMAND) end def run_on_changes(paths) run_all end end end ! guard :inline_guard do watch /.*\.[mh]$/ end
  13. xcpretty gem install xcpretty ! xcodebuild test \ -scheme $(SCHEME)

    \ -destination $(DESTINATION) \ | xcpretty -c
  14. TKRSpecificTest xcodebuild test \ -scheme $(SCHEME) \ -destination $(DESTINATION) \

    GCC_PREPROCESSOR_DEFINITIONS='TEST_ONLY=\"TestCase\"'
  15. XCTestObserver @interface XXXObserver : XCTestObserver @end ! @implementation XXXObserver -

    (void)stopObserving { [super stopObserving]; extern void __gcov_flush(void); __gcov_flush(); } ! @end
  16. CI

  17. σʔλͷ഑෍ • ͜ͷKeynote •=> Speaker DeckʹΞοϓ͠·͢ • αϯϓϧίʔυ •https://github.com/tokorom/CompareObjcMatcher •https://github.com/tokorom/

    ReplaceImageCategoryForXcode •https://github.com/tokorom/TKRGuard •https://github.com/tokorom/TKRSpecificTest !