Last week, we talked about why you shouldn’t unit test private methods. Today we’ll talk about why you should. Wait, what? I just told you that unit testing private methods was unnecessary because you can just test the public methods that call them. However, I was making a big assumption when I said that. I was assuming your public methods …
Can I unit test private methods?
I’ve heard a variation of this question over and over: “Can I unit test private methods?” It comes in other forms, too, like “how do I verify that one method in a class called another method in the same class?” The answer is: you don’t. You don’t verify that one method in a class called another method in that class. …
Dave DeLong, in A Better MVC, Part 5: An Evolution: “As I examined UIViewController and its role in apps more, I came to the conclusion that, despite its name, UIViewController is not a Controller, but a View. Almost everything that UIViewController deals with relates to view-level concepts, which heavily implies that it itself is a View, and should be treated …
How to unit test button taps on a view controller with XCTest
In the previous article in this series, we verified that our LoginViewController meets certain requirements for displaying text. When those tests pass, we have proof that our LoginViewController has the title “Podcaster” and that the username field’s placeholder text is “Username or email”. While tests like those are certainly useful for offloading some of the mental burden of manual testing, …
What’s the difference between a mock and a stub, and how do you use them in Swift?
(Northern Mockingbird. Public domain.) Lots of people use the terms “mock” and “stub” interchangeably, and there’s a good deal of confusion around them. But mocks aren’t stubs, as Martin Fowler says — they behave a bit differently. So what’s the difference between a mock and a stub, and how do you use them to test your code? Stubbing in Swift …
How to write unit tests in Swift 4 with XCTest
Convinced of the benefits of unit testing for iOS but not sure where to start? Trying to figure out what framework to use, how to set it up, and which test to write first can feel overwhelming. What unit testing framework should you use? XCTest. Here’s why: it works well, it’s easy to set up, and it’s easy to use. …
What are the benefits of unit testing?
When I asked my mailing list “What keeps you from writing unit tests?” one person said “I just don’t really understand the value of them.” And it wasn’t just that person — the majority of responses fit into that category. Generally speaking, iOS developers don’t write unit tests because they don’t know what the benefits are. Let’s look at all …
Not Using Automated Tests: Still a Systemic Problem for iOS Developers
Ash Furrow, over five years ago, in Seven Deadly Sins of Modern Objective-C: Do you unit test your Objective-C? No, you probably don’t. Do you have automated UI acceptance tests for your UI? Nope. Do you have any kind of continuous integration set up? No, you don’t. I don’t understand what is wrong with the Objective-C community that it continuously …
Why iOS developers don’t write unit tests
Last week I asked my mailing list “What keeps you from writing unit tests?” and got more than 30 responses. (If you didn’t participate and want to, just send me an email with your answer to josh@roadfiresoftware.com.) Today I’m sharing the anonymized results, hoping they’ll help all of us become more aware of why we don’t write unit tests — …
What framework should I use to start unit testing on iOS?
If you want to get started quickly, don’t waste your time searching for a good unit testing framework — just use the XCTest framework. It’s built in to Xcode, easy to set up, easy to use, and works well. When you’re writing your first unit tests for iOS, you don’t need the distraction of researching a new third-party library, especially …