longestdrive's avatar

laravel testing: avoiding repeating similar tests

Hi I'm trying to find a better way to test my code as I find myself repeating similar tests.

As an example I have a class (Class A) that within it's functions calls on functions within another class (Class B)

Class A gets the result of a function in Class B and it then does something with it.

In my tests I start with testing the functions within Class B and make sure it's producing the results I need.

I then start testing Class A and check it's doing what it needs to with the results from Class B but in doing so it feels as if I'm retesting Class B - I want to make sure they work together and the results are as expected.

I thought about mocking - which I'm not overly comfortable with as I thought that because Class A needs the results from Class B to do it's thing I'm going to have to create dummy data for Class A to use (which feels like an effort when Class B can do that without my help)

So...how can I improve my approach - should I embrace and dig deeper into mocking to avoid duplication?

0 likes
0 replies

Please or to participate in this conversation.