Introducing Laravel Test WatcherWacky StudioBlockedUnblockFollowFollowingApr 3We are proud to announce Laravel Test Watcher ????Laravel Test Watcher is a package for Laravel which makes it possible to run your tests automatically whenever there is a change to your source files.
You might have heard about tools like this before, but Laravel Test Watcher is not like other test watchers out there.
Instead of running your entire test suite whenever there is a file change, Laravel Test Watcher lets you specify single test cases and test these on file changes instead.
It makes it possible to run only the tests you are interested in and get the results much faster, resulting in a much better feedback loop.
This makes Laravel Test Watcher perfect for when you are implementing a feature, where the tests for that feature might span over multiple test cases, in various files.
How does it work?You start Laravel Test Watcher through the dedicatedtests:watch artisan command, which will make Laravel Test Watcher listen for file changes.
You then go into your test files and specify the test cases you want to test through a @watch annotation.
By adding this annotation above the test case you want to test Laravel Test Watcher will automatically register the test case and run the test whenever you save a change to your source code, like this:In the example above, the first_feature_test test case is registered by Laravel Test Watcher.
When registering your test case Laravel Test Watcher will show you both the test case and the file the method belongs to like this:A newly registered test caseWhen you are done testing this case, you merely remove the @watch annotation from the test case and Laravel Test Watcher will automatically stop testing this case on file changes.
The @watch annotation was removed, and there are no test cases to watchWhenever you save changes to a file Laravel Test Watcher will run the test and give you feedback on whether it has been a success by coloring the case names green:Succeeding testIf a test should fail it will be colored red, and beneath the list of test files and cases, the error messages will be shown:Failing testAs we have mentioned earlier, Laravel Test Watcher can watch multiple test cases in various files.
Laravel Test Watcher will list your test files and cases in a column structure so you can easily see which tests in which files are succeeding or failingThe ideaAfter going through Marcel Pociot’s PHP Package Development course, we got inspired and wanted to do some package development again.
We have some ideas we have been tinkering with for quite some time, but the idea for this package came while writing our book Build an API with Laravel.
While writing the chapter about test-driven development, we realized that there isn’t a common workflow for running tests across both platforms, IDEs, and editors, other than running PHPUnit manually from the terminal, which will run your entire test suite, unless you type out the specific tests you want to run, or group them and then run PHPUnit for that group.
We use PHPStorm which makes it super easy to run and rerun a specific test case, giving a quick feedback loop while developing your feature.
This way of testing is a big part of our workflow, especially when building APIs.
It’s something we teach about in our book since it’s a workflow we feel others can benefit from too.
But we don’t want to force the readers of our book to purchase PHPStorm to follow along.
Therefore we decided to build this package.
We hope you will enjoy using the package and we hope it will boost your workflow as well.
If you want to learn more about how to use it or want to learn more about how to build APIs with Laravel check out our book at https://buildanapi.