RunnerTests.m 3.33 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
@import XCTest;
@import integration_test;
7

8 9
#pragma mark - Dynamic tests

10
INTEGRATION_TEST_IOS_RUNNER(RunnerTests)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

@interface RunnerTests (DynamicTests)
@end

@implementation RunnerTests (DynamicTests)

- (void)setUp {
  // Verify tests have been dynamically added from FLUTTER_TARGET=integration_test/extended_test.dart
  XCTAssertTrue([self respondsToSelector:NSSelectorFromString(@"testVerifyScreenshot")]);
  XCTAssertTrue([self respondsToSelector:NSSelectorFromString(@"testVerifyText")]);
  XCTAssertTrue([self respondsToSelector:NSSelectorFromString(@"screenshotPlaceholder")]);
}

@end

#pragma mark - Fake test results

@interface IntegrationTestPlugin ()
- (instancetype)initForRegistration;
@end

@interface FLTIntegrationTestRunner ()
@property IntegrationTestPlugin *integrationTestPlugin;
@end

@interface FakeIntegrationTestPlugin : IntegrationTestPlugin
@property(nonatomic, nullable) NSDictionary<NSString *, NSString *> *testResults;
@end

@implementation FakeIntegrationTestPlugin
@synthesize testResults;

- (void)setupChannels:(id<FlutterBinaryMessenger>)binaryMessenger {
}

@end

#pragma mark - Behavior tests

@interface IntegrationTestTests : XCTestCase
@end

@implementation IntegrationTestTests

- (void)testDeprecatedIntegrationTest {
  NSString *testResult;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  BOOL testPass = [[IntegrationTestIosTest new] testIntegrationTest:&testResult];
#pragma clang diagnostic pop
  XCTAssertTrue(testPass, @"%@", testResult);
}

- (void)testMethodNamesFromDartTests {
  XCTAssertEqualObjects([FLTIntegrationTestRunner
                         testCaseNameFromDartTestName:@"this is a test"], @"testThisIsATest");
  XCTAssertEqualObjects([FLTIntegrationTestRunner
                         testCaseNameFromDartTestName:@"VALIDATE multi-point 🚀 UNICODE123: 😁"], @"testValidateMultiPointUnicode123");
  XCTAssertEqualObjects([FLTIntegrationTestRunner
eggfly's avatar
eggfly committed
70
                         testCaseNameFromDartTestName:@"!UPPERCASE:\\ lower_separate?"], @"testUppercaseLowerSeparate");
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
}

- (void)testDuplicatedDartTests {
  FakeIntegrationTestPlugin *fakePlugin = [[FakeIntegrationTestPlugin alloc] initForRegistration];
  // These are unique test names in dart, but would result in duplicate
  // XCTestCase names when the emojis are stripped.
  fakePlugin.testResults = @{@"unique": @"dart test failure", @"emoji 🐢": @"success", @"emoji 🐇": @"failure"};

  FLTIntegrationTestRunner *runner = [[FLTIntegrationTestRunner alloc] init];
  runner.integrationTestPlugin = fakePlugin;

  NSMutableDictionary<NSString *, NSString *> *failuresByTestName = [[NSMutableDictionary alloc] init];
  [runner testIntegrationTestWithResults:^(SEL nativeTestSelector, BOOL success, NSString *failureMessage) {
    NSString *testName = NSStringFromSelector(nativeTestSelector);
    XCTAssertFalse([failuresByTestName.allKeys containsObject:testName]);
    failuresByTestName[testName] = failureMessage;
  }];
  XCTAssertEqualObjects(failuresByTestName,
                        (@{@"testUnique": @"dart test failure",
                           @"testDuplicateTestNames": @"Cannot test \"emoji 🐇\", duplicate XCTestCase tests named testEmoji"}));
}

@end