Does stubbing give you an empty feeling – am I stubbing too much?

As you start writing your first few unit tests, this is how you’re going to feel.

You’re testing a class, then you need to stub out some other class, and some more class. Eventually, you’ll feel like you’re basically stubbing everything. You don’t even know if you’re still testing the real class anymore.

I feel this pain when I first started unit testing many years ago. So I completely understand why you’re feeling this way. And I’m going to give you a magic pill for this pain to go away forever.

I came across the following question in Slack the other day:

Lets say that I have some CommentsWebSocket – and I inject it into in my view controller. Is there a reason to make CommentsWebSocketStub in order to inject it into the sut when testing the view controller?

Continue reading →

Data independence is key to robust architecture and non-fragile unit tests

I have an 8-year old girl who rides the school bus to go to her school every morning. So we’ve waited for the school bus together on the sidewalk. But some day I drove behind a school bus and had to stop when the bus stopped to allow the kids cross the street safely.

With nothing to do, I looked at the school bus and noticed something. It has a different vehicle number than the route number. My girl remembers her route number on the very first day of school. But we never knew there’s also a vehicle number.

And there’s a reason for that, and a lesson to learn. The vehicle number is for the mechanics, whereas the route number is for the students. The same bus is presented to the mechanics and the students differently, so that the information is useful, and not a hindrance.

We can apply this simple HIG from the real world to our code.

Continue reading →

Should you check in your dependencies?

No matter the platforms you develop on, any sane developer knows it’s prudent to use a source code repository and check in their commits when progress is made. This is just common sense among us. But what about your dependencies?

Should you also check in your dependencies? In the iOS world, that means CocoaPods or Carthage.

The short answer is yes. You should always check them in.

For the longer answer, …

Continue reading →

How to add reactive-ness to Clean Swift

I answered different forms of this same questions many times in emails, comments, and my mentorship program. I understand why people ask this question. They’ve seen MVVM, ReactiveCocoa, RxSwift, and want to see if Clean Swift can handle this model-view update automatically.

My answer is always the same. You don’t need it. You don’t need to add yet another dependency just to do this simple thing.

Your interactor can invoke a method of the presenter multiple times, and/or invoke multiple methods of the presenter.

The following is taken directly from a discussion in my mentorship program.

Continue reading →