Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure tests are only run on iPhone 8 #692

Merged
merged 3 commits into from
May 30, 2019
Merged

Conversation

justinswart
Copy link
Contributor

@justinswart justinswart commented May 29, 2019

📲 What

Ensures that we only run tests and record screenshots on the iPhone 8 simulator.

If for whatever reason we need to run unit tests on a different device, we can just comment out this line.

🤔 Why

It's happened once or twice in the past that we accidentally record a bunch of screenshots on the wrong device which results in thousands of new screenshots being committed to the repo. This is just a safety catch to help us prevent that.

🛠 How

Put a check at the top of TestCase setUp() function which is called before all tests run.

✅ Acceptance criteria

  • All tests pass as before.
  • Running tests on any other device causes Xcode to fail and to not continue running tests.

@ksr-ci-bot
Copy link

SwiftFormat found issues:

File Rules
Library/TestHelpers/TestCase.swift redundantSelf, sortedImports

Generated by 🚫 Danger

@@ -25,6 +25,12 @@ internal class TestCase: FBSnapshotTestCase {

override func setUp() {
super.setUp()

let preferredDeviceName = "iPhone 8"
if !UIDevice.current.name.contains(preferredDeviceName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be getting this from AppEnvironment.current so that we can potentially inject our own value down the road (and maybe for consistency)?

Copy link
Contributor Author

@justinswart justinswart May 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is really for AppEnvironment, that's only for dependency injection and I don't know that we'd want to inject stuff in unit tests for unit tests 🤔 I think this is like a safety thing much like we have in our swiftlint.yml to fail if we leave self.recordMode = true in the test.

Scollaco
Scollaco previously approved these changes May 30, 2019
Copy link
Contributor

@Scollaco Scollaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

dusi
dusi previously approved these changes May 30, 2019
Copy link
Contributor

@dusi dusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test seems to fail on iPhone 8 / iOS 11 .. which is actually good because there could be minor differences due to UIKit's rendering so I think right now this is the right way to go!

Thanks @justinswart this is super helpful!

@justinswart justinswart dismissed stale reviews from dusi and Scollaco May 30, 2019 17:26

Please check the improvement

Copy link
Contributor

@dusi dusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job...this will make our testing more robust!

giphy

@justinswart justinswart merged commit 1191a6b into master May 30, 2019
@justinswart justinswart deleted the tests-iphone-8-only branch May 30, 2019 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants