Database Reference
In-Depth Information
Chapter 8: Unit Testing
By Aaron Douglas
Unit testing is a testing method where the goal is to test small pieces (or “units”) of
software. Rather than test “the app creates a new record when you tap the button”
you might break this down into testing the button touch-up event, creating the
entity, testing whether the save succeeded, and so on.
Why should you care about unit testing your apps? There are lots of reasons:
Unit testing helps you work out the architecture and behavior of your app at a
very early stage. You can test much of the app's functionality without needing to
worry about the UI.
Unit testing gives you the confidence to add features or refactor, knowing that
you haven't broken other parts of the app. If you have existing tests that pass,
you can be confident that the tests will fail and give you a warning if you break
something later.
When working on projects with multiple developers, unit tests can help keep you
all on the same page and ensure that each developer can make changes
independently.
If you've ever found yourself working on a particular feature of an app and each
time you want to check it out, you have to tap through three different screens
and enter some data, unit testing is your new best friend. You can run any part of
your app's code from a unit test, which is much faster than testing “manually”
through the UI.
In this chapter, you'll learn how to use the XCTest framework in Xcode to test your
Core Data apps. Unit testing Core Data apps isn't as straightforward as it could be,
because most of the tests will depend on having a valid Core Data stack. You might
not want a mess of test data from the unit tests to interfere with your own manual
testing done in the simulator or on device, so you'll learn how to keep the test data
separate.
You'll get a good introduction to XCTest in this chapter, but you should have a basic
understanding of it already to make the most from this chapter. For more
information, check out Apple's documentation
( https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual
 
Search WWH ::




Custom Search