Dynamically add integration_tests and screenshots to native iOS test results (#95704)
This commit is contained in:
@@ -25,6 +25,24 @@ void main() {
|
||||
// Build our app.
|
||||
app.main();
|
||||
|
||||
// Pump a frame.
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify that platform version is retrieved.
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(Widget widget) =>
|
||||
widget is Text &&
|
||||
widget.data!.startsWith('Platform: ${Platform.operatingSystem}'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('verify screenshot', (WidgetTester tester) async {
|
||||
// Build our app.
|
||||
app.main();
|
||||
|
||||
// On Android, this is required prior to taking the screenshot.
|
||||
await binding.convertFlutterSurfaceToImage();
|
||||
|
||||
@@ -39,15 +57,5 @@ void main() {
|
||||
expect(secondPng.isNotEmpty, isTrue);
|
||||
|
||||
expect(listEquals(firstPng, secondPng), isTrue);
|
||||
|
||||
// Verify that platform version is retrieved.
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(Widget widget) =>
|
||||
widget is Text &&
|
||||
widget.data!.startsWith('Platform: ${Platform.operatingSystem}'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,20 @@
|
||||
ReferencedContainer = "container:Runner.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "NO"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "769541C723A0351900E5C350"
|
||||
BuildableName = "RunnerTests.xctest"
|
||||
BlueprintName = "RunnerTests"
|
||||
ReferencedContainer = "container:Runner.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
|
||||
@@ -5,4 +5,89 @@
|
||||
@import XCTest;
|
||||
@import integration_test;
|
||||
|
||||
#pragma mark - Dynamic tests
|
||||
|
||||
INTEGRATION_TEST_IOS_RUNNER(RunnerTests)
|
||||
|
||||
@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
|
||||
testCaseNameFromDartTestName:@"!UPPERCASE:\\ lower_seperate?"], @"testUppercaseLowerSeperate");
|
||||
}
|
||||
|
||||
- (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
|
||||
|
||||
Reference in New Issue
Block a user