ryan_'s avatar
Level 4

Test Won't work

when i create a unit test even when i do every thing correct the test fails, but when i move the same test to feature test it passes . any ideas

0 likes
7 replies
Tray2's avatar

Yes, The Feature test extends the Laravel Testcase class while the unit test extends the PhpUnit Testcase,

3 likes
ryan_'s avatar
Level 4

@Tray2 So how do i write unit tests? i've been following the "build a laravel app with Tdd" and the same code work in the video and does not work for me (* i'm a biginner *)

1 like
Sinnbeck's avatar

@ryan_ If you need to hook into laravel features it's a feature test. Unit tests is for testing an emcapsuled action. Like calculating the average of a bunch of numbers. Just test 1 unit of code

But you are not forced into any structure. You could just extend laravels test class in all tests and move them into folders that makes sense to you.

You can see here how laravel itself structures it https://github.com/laravel/framework/tree/9.x/tests

2 likes
Tray2's avatar
Tray2
Best Answer
Level 74

@ryan_ Either don't use any Laravel Testcase methods in your unit test or just extend the Laravel testcase in the unit tests as well instead of the PhpUnit testcase.

2 likes
Sinnbeck's avatar

@ryan_ Remember to mark his answer as best if it solved the problem :)

1 like
Sarah Smith 's avatar

refactoring your code this process achieves functionality.

Please or to participate in this conversation.