topvillas's avatar

Model Test Coverage

Hey peeps.

I'm mucking about with an experimental project to do with multiple user types. I've taken the approach of using a base User that extends Illuminate\Foundation\Auth\User and a polymorphic relationship to other plain models. The question isn't about that though.

I'm using Pest to do my testing (check it out at https://pestphp.com) and I've just installed XDEBUG 2.0 to show my test coverage, Currently the percentage for all my user type models is zero. So, my question is, how do I test these models for total coverage? What do I need to test if they currently have no methods or their own?

0 likes
7 replies
tykus's avatar
tykus
Best Answer
Level 104

What do I need to test if they currently have no methods or their own?

Nothing. Full Coverage does not mean your application is well tested; (apparent) lack of coverage doesn't mean is is not well tested.

topvillas's avatar

I see, so 0% if there is nothing to test is just a bit misleading and pessimistic then?

tykus's avatar

Not really misleading; if there is nothing there to be tested, then 0% coverage is an accurate representation IMHO. The expectation that everything should be green in the coverage report is unrealistic (again IMHO), it leads to tests being written that do not add real value.

topvillas's avatar

Thanks, Tykus. I did hear somewhere that there comes a point when the time spent writing tests outweighs their usefulness.

martinbean's avatar

@topvillas 100% code coverage doesn’t mean your code is 100% bug-free.

Don’t write tests for the sake of code coverage. Write tests to test your application and its logic.

automica's avatar

@topvillas tests should be written as you write your methods. they should be a scaffolding to help out your methods.

if you approach it by TDD then all your valuable methods have code coverage.

topvillas's avatar

Thanks for the responses, peeps.

Very helpful.

Please or to participate in this conversation.