Support the ongoing development of Laravel.io →
posted 9 years ago
Testing

I have a Model method that makes use of several methods from other classes (Some from third party libraries, some from helper classes, etc.). When unit testing this method, I am mocking every method called in that original method. Everything works fine.

However, the test method is too long to my liking (40 lines!). The actual testing code is only 2 lines, the rest is preparing mock methods and instructing Laravel to use the mocks in place of the real methods.

Is this normal? In many places I saw people recommending unit tests to be small, but having mocks in there makes it impossible to make it small. How would you proceed?

Last updated 3 years ago.
0

if you are mockng these things in other methods then maybe split them out to another function.. & use this test class's variables..

0

Sign in to participate in this thread!

Eventy

Your banner here too?

budhajeewa budhajeewa Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.