3 ms·
I agree with a TDD, but it really depends on the framework/cms you're working, some of them are incredibly hard to write tests agaist. One of the examples would
by insanebits 11y ago
I agree with a TDD, but it really depends on the framework/cms you're working, some of them are incredibly hard to write tests agaist. One of the examples would be writing unit tests for the WordPress plugin, if you're sticking to the WordPress way of coding unit testing is practically impossible because there is lot's of database access and events which do mess up.
You can write plugin folowing OO principles and abstract things out to be able to mock them as nessesery. It really depends on the coding standarts you're folowing.
As for unit testing. In my personal experience it enforces you to write cleaner code, because when I started I had to do heavy refactoring to be able to test my prototype, but as I wrote more testable code I started separate unrelated parts which reduced amount of spagetti code.
Another way to achieve cleaner code in my opinion would be design patters which lets you separate code logically(for example MVC), and make some things cleaner(I'm big fan of laravel's Facades for example).