IntegrationTestIosTest.h 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 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
// 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.

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol FLTIntegrationTestScreenshotDelegate;

@interface IntegrationTestIosTest : NSObject

- (instancetype)initWithScreenshotDelegate:(nullable id<FLTIntegrationTestScreenshotDelegate>)delegate NS_DESIGNATED_INITIALIZER;

/**
 * Initate dart tests and wait for results.  @c testResult will be set to a string describing the results.
 *
 * @return @c YES if all tests succeeded.
 */
- (BOOL)testIntegrationTest:(NSString *_Nullable *_Nullable)testResult;

@end

#define INTEGRATION_TEST_IOS_RUNNER(__test_class)                                           \
  @interface __test_class : XCTestCase<FLTIntegrationTestScreenshotDelegate>                \
  @end                                                                                      \
                                                                                            \
  @implementation __test_class                                                              \
                                                                                            \
  - (void)testIntegrationTest {                                                             \
    NSString *testResult;                                                                   \
    IntegrationTestIosTest *integrationTestIosTest = integrationTestIosTest = [[IntegrationTestIosTest alloc] initWithScreenshotDelegate:self]; \
    BOOL testPass = [integrationTestIosTest testIntegrationTest:&testResult];               \
    XCTAssertTrue(testPass, @"%@", testResult);                                             \
  }                                                                                         \
                                                                                            \
  - (void)didTakeScreenshot:(UIImage *)screenshot attachmentName:(NSString *)name {         \
    XCTAttachment *attachment = [XCTAttachment attachmentWithImage:screenshot];             \
    attachment.lifetime = XCTAttachmentLifetimeKeepAlways;                                  \
    if (name != nil) {                                                                      \
      attachment.name = name;                                                               \
    }                                                                                       \
    [self addAttachment:attachment];                                                        \
  }                                                                                         \
                                                                                            \
  @end

NS_ASSUME_NONNULL_END