mosesnagar's avatar

how to know if its unit test or feaute

hi, i'm quite new in testing. how do i know if its unit test or feature ? for example, i want to test my models. i have User, Forum, Topic and Comment with relationships between them. when i want to test their realtionships for one hand its like unit test - i am testing a small part, a method. for the other hand its a feature because it test the model with other models so their is some of integration.

u have an idea?

0 likes
3 replies
bobbybouwmann's avatar
Level 88

Well most of the time unit tests are used for small units and features are used for more integration tests. For example when you want to test a relationship you need to write a feature test because it uses a database to properly test it. For example an algorithm is a unit test because you test a small independent feature!

However in Laravel you can also perform unit tests using the database depending on the class you extend. For example extending the TestCase class is a feature in general. However if you extend the PHPUnit\Framework\TestCase it's a real unit test because it has no knowledge of Laravel.

So in general I would keep the role that if the test is Laravel independent it's a unit test and otherwise a feature test!

Hope that helps a bit!

bobbybouwmann's avatar

I would write a feature test for that instead of a unit test ;)

Please or to participate in this conversation.