Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
nitnip18083yCareful.
If all your tests are mocks, they lose the ability to be tests and instead become some sort of spec document detailing what should happen rather than testing against what is actually happening. -
killames5733y@nitnip well part of it is testing for fail points in your choice of software libs and the like too
Like request promise throws in catchable exceptions sometimes -
@nitnip It should be clear what you're testing and what you're mocking...
But you don't want to create a user, fill a shopping cart, go through checkout and shipping for every test of the invoice system.
And while sometimes testing database persistence is useful, you certainly don't want your tests to depend on external APIs outside of your control. Not even sandbox APIs. -
@nitnip I am very pro “test the actual code”. But there are many situations where that’s not possible or practical.
My use case is a third party library that has an embedded social media login feature. I have to put a lot of logic around this and want to test that. But I can’t have my unit tests logging into Twitter accounts. So I need a way to mock that and just return a dummy object from this SDK
This library has a shit tonne of classes and constructors marked as private or final so I can’t subclass or touch them. And the networking code is hidden away so I can’t stub that either
Related Rants
*Achievement unlocked*
The award of:
Asking “Can you please fucking enable some way for me to mock the networking requests?” A record number of times to unique third party libraries in a week
Awarded to:
practiseSafeHex
rant
di mother fuckers
mock
live by the mock
mock or die