How To Say No Like A Product Manager

There is a misconception among new product managers — heck, even some experienced ones — that the job of a product manager requires us to agree to everything that is proposed to us, either from the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Mocking in Swift

When I started learning about what defines a good unit test, an important concept to remember was that good unit tests should be isolated and that the goal of a single unit test is to verify that a specific unit of our code works properly while being isolated from the rest of the system. This means that if for example, we have a Shop class that contains a method sellItem(:item) and if we want to write a unit test that will test the behavior of sellItem(:item), our unit test should not care at this point about the implementation details of the item argument that sellItem(:item) accepts. If our unit test cares about the implementation details of the item argument, this means that our unit test is not isolated and actually at this point, we might not be able to call it a unit test anymore. It’s more of an integration test now.

To make our unit test isolated and not forced to work with other parts of our code that might introduce other problems, we have to fake those other parts that we don’t want to depend on or care about. During my development years, there has been lots of confusion about what does faking means here. After reading a few books and articles on the subject, I found that there are many ways to fake the behavior of the objects that we don’t care about. Those objects, in this case, can get many different names: “mocks, stubs, dummies, fakes, spies,..”. I used to get confused all the time when I heard those words. At some point, they all seemed very similar to me. Many times I used to refer to stubs as mocks and vice versa, but thankfully I learned more about the differences as I progressed in my career. I hope that I have a better understanding of those concepts now and that I can help you understand them too.

There are different types of “Test Doubles” that we might need for writing our tests. While the definitions can be slightly different among developers, I would love to share my understanding in this article and hear any other definitions or thoughts about them. This is a list of the most common “Test Doubles” used in the testing world:

Add a comment

Related posts:

10 Korean Celebrities Change Their Smiles

Getting your teeth fixed can be life-changing. Imagine looking in the mirror and loving your smile, instead of noticing all the things you don’t like about it. That’s the experience that 10 Korean…

Amal journey

I hope to continue writing blogs even after the Amal fellowship ends. Yeah, it is surprising that this three-month journey passed like the wind. I was so happy that finally the period of misery came…

Senate Leader to Legalize Hemp in the US

The top Republican in the U.S. Senate wants to legalize hemp. Senate Majority Leader Mitch McConnell introduced a bill on Thursday, April 12, that would remove federal barriers to hemp, which is…