XCTest没有按顺序排序方法的能力,所以我在方法的命名约定中使用了旧的hack来强制执行测试订单:
testHomePage
testLogin
到
test01Login
test02Hompage
曾经在 Xcode 7 Swift 2.2
中工作在 Xcode 8 / Swift 3 中,这似乎不再适用了!那么 Xcode 8 / Swift 3 没有字母,顺序或任何排序逻辑?
我和我的团队调查了可能会修改 pbx / xml 文件,但也没有任何可编辑的文件。任何人都建议如何强制执行测试以按特定顺序运行?
答案 0 :(得分:0)
我会重构以避免强制执行订购。即使这些是UI测试,而不是单元测试,我认为同样的原则适用:每个新测试应该从一个新系统开始。
因此,例如,重构逻辑以进行登录(不进行任何测试),并在需要登录用户的所有测试中使用它。您还需要一种能够重置"的方法。在某种意义上的系统 - 所以在你的情况下,也许记录用户。根据我的经验,从setup
方法而不是teardown
方法更好地调用它,因为如果测试由于某种原因意外停止,则下一次测试运行将始终失败。
这种方法的缺点是你的测试需要更长的时间才能运行,因为你的应用程序将反复登录和注销,但这一事实应该鼓励你完全专注于UI并保持更加繁琐的逻辑细节(用户名)字符串长度,密码有效性等。)在您的单元测试中。
答案 1 :(得分:0)
我们发现这是一个帮助UI测试执行顺序的解决方案。
以下是一个独立运行的测试示例,另一个需要按顺序排序的测试示例:
test_search:
stage: test
tags:
- ios
script:
- xcodebuild test-without-building -workspace company.xcworkspace -scheme yourcompany -destination 'platform=iOS Simulator,name=iPhone 7,OS=latest' -only-testing:Test/testSearch
test_profile_and_edit:
stage: test
tags:
- ios
script:
- xcodebuild test-without-building -workspace company.xcworkspace -scheme your company -destination 'platform=iOS Simulator,name=iPhone 7,OS=latest' -only-testing:Test/testProfile
- xcodebuild test-without-building -workspace company.xcworkspace -scheme your company -destination 'platform=iOS Simulator,name=iPhone 7,OS=latest' -only-testing:Test/testProfileEdit
如果您有需要登录的方案,请在安装程序中包含覆盖方法以检查用户是否已登录。