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

Unit test refactors #9

Merged

Conversation

joemasilotti
Copy link
Contributor

Here's a first pass at making ViewController a little more testable. I'm following the techniques I've outlined in Better Unit Testing with Swift, namely:

  • inject static dependencies
  • make dependencies protocols
  • make all value types equatable

First, I made USPSManager conform to a new protocol, PackageManager. This allows us to create a mock for use under tests. Then, to make assertions easier, I moved the class methods to instance methods. Now the mock can record each parameter that was passed to it under test (and call the completion block with mock data!).

This required opening up the packageManager variable on ViewController. Ideally, this would be a let variable and injected via the initializer. However, I wasn't able to get this to work with storyboards so I figured a lazy-evaluated var was a good tradeoff.

Finally, the tests set up some mock package tracking information then assert that the table shows said data.

@SixFiveSoftware
Copy link
Contributor

👍 Looks great, thanks!

SixFiveSoftware added a commit that referenced this pull request Dec 1, 2015
@SixFiveSoftware SixFiveSoftware merged commit 299041d into ConceptsInCode:develop Dec 1, 2015
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

2 participants