@jeffreyway has videos on testing. Some are free. But I'd say yes test certain methods, I don't know about testing a whole controller.
How do you UNIT test your controller?
Hi. I really dont do unit testing on my controllers classes. And I just got a tasks that requires me to do it. can you guys give me some idea on how to UNIT test a controller class ?
@kevdev You wouldn’t unit test a controller. A unit test should test one single unit of code (such as a method) without dependencies. It’s nigh-on impossible to unit test a controller because it relies on so much context: a router, middleware, requests and responses, etc.
You’ll find difficulty unit-testing a controller as Laravel’s unit test classes extends PHPUnit’s base TestCase class. Instead, you’ll need to create a feature test, which boots the framework in their setUp methods, and will give you helpers for testing HTTP requests such as $this->post, $this->assertSuccessful, etc.
If you’re writing a unit test and struggling because you need access to the framework, or resources like a database, then that’s a good indicator that what you’re writing is not a unit test.
Please or to participate in this conversation.