问题
Is it possible to run Flutter integration tests on Firebase? There seems to be conflicting info on this - some sources say its possible, but on the documentation, the iOS section seems to only be for testing on your own device.
Firebase asks for an XCT test package to be uploaded. How can it be obtained / created for a Flutter project?
回答1:
First of all open your ios Module in Xcode as ss below.
Now you are free to write cool XCode UI tests with Swift. For example I am dropping here a Firebase Login test for your app maybe you wish to use.
import XCTest
import UIKit
import Firebase
class LoginTestUITests: XCTestCase {
var app: XCUIApplication!
func testLogin() {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
wait(for: 2)
passLogin()
wait(for: 5)
// after your login you can add some methods here according to your app flow
}
}
extension LoginTestUITests {
func passLogin() {
//put your logic here
}
// this is a pretty cool extension waiting according to input for a while coming the data from backend etc.
extension XCTestCase {
func wait(for duration: TimeInterval) {
let waitExpectation = expectation(description: "Waiting")
let when = DispatchTime.now() + duration
DispatchQueue.main.asyncAfter(deadline: when) {
waitExpectation.fulfill()
}
// I use a buffer here to avoid flakiness with Timer on CI
waitForExpectations(timeout: duration + 0.5)
}
}
回答2:
You need to have Xcode to do it. If you are using Android first open iOS module in Xcode
Then in Xcode open the Test navigator (Command-6) and add new test target:
Now we have two targets for Unit and UI test in our Flutter project
Our project is ready for test and we can check it run Product ▸ Test or Command-U in Xcode:
Then Firebase Test Lab:
- iOS: Write XCTests, then build and package your app for upload.
Just create application package using Xcode Product > Archive selecting real device as a target.
回答3:
Open Xcode project (by default, it's ios/Runner.xcodeproj). Create a test target (navigating File > New > Target... and set up the values) and a test file RunnerTests.m and change the code. You can change RunnerTests.m to the name of your choice.
#import <XCTest/XCTest.h>
#import <integration_test/IntegrationTestIosTest.h>
INTEGRATION_TEST_IOS_RUNNER(RunnerTests)
来源:https://stackoverflow.com/questions/66042050/flutter-integration-tests-for-ios-on-firebase