As I progress with my DojoList project I am trying to be a good boy and integrate coding standards (via PHPCodeSniffer ) and also automated testing.
My tetsing is presently using SimpleTest for PHP. As I progress through the project I am trying to be stricter with myself and write more and more tests.
Part of this attempt at discipline is to write tests against my bugs BEFORE I write fixes for them. This is a test Driven Development (TDD) idea, and it is one I think is worth using.
The idea here is that you write a little bit of code that hits your bug, then after you have a test (that fails) you make your fix and re-run the test... and the test should then pass.
One of the benefits of working this way is that you have to isolate the bug so you can write a test for it. This forces you to delve pretty deep into the bug and understand it, before you start trying to fix it at all.
This also leads you to identifying messy bits of your code. Basically, if it's hard to isolate and test your bug, it's probably becuase your code is not abstracted out nicely. Writing tests for bugs can lead you to modify your models/controllers/classes/whatever to make it easier to test just the buggy part of your code.
Writing a test for a bug, also lets you leave an artifact that shows you addressed the issue, in code. So for example you can leave a comment in the test that states what bug you are testing for.
Obviously, it also means that latter on in the codes life, that bug should not creep back in as you test for it everytime.
I have found that writing tests for bugs is helping persuade me to write tests for new pieces of functionality before I code them. In other words writing tests for bugs is a bit of a "gateway drug" to full test driven development (TDD).
I find the urge to write tests first growing the more bugs I start squashing. This is all leading to stronger code. And code I am more comfortable playing with.
You develop a trust in your tests, you know that if you mess something up (and you will), your tests will save you from going on after a mistake.
All in all, writing bugs has been a really positive experience that is leading me towards writing more code in full TDD mode in future.
My tetsing is presently using SimpleTest for PHP. As I progress through the project I am trying to be stricter with myself and write more and more tests.
Part of this attempt at discipline is to write tests against my bugs BEFORE I write fixes for them. This is a test Driven Development (TDD) idea, and it is one I think is worth using.
The idea here is that you write a little bit of code that hits your bug, then after you have a test (that fails) you make your fix and re-run the test... and the test should then pass.
One of the benefits of working this way is that you have to isolate the bug so you can write a test for it. This forces you to delve pretty deep into the bug and understand it, before you start trying to fix it at all.
This also leads you to identifying messy bits of your code. Basically, if it's hard to isolate and test your bug, it's probably becuase your code is not abstracted out nicely. Writing tests for bugs can lead you to modify your models/controllers/classes/whatever to make it easier to test just the buggy part of your code.
Writing a test for a bug, also lets you leave an artifact that shows you addressed the issue, in code. So for example you can leave a comment in the test that states what bug you are testing for.
Obviously, it also means that latter on in the codes life, that bug should not creep back in as you test for it everytime.
I have found that writing tests for bugs is helping persuade me to write tests for new pieces of functionality before I code them. In other words writing tests for bugs is a bit of a "gateway drug" to full test driven development (TDD).
I find the urge to write tests first growing the more bugs I start squashing. This is all leading to stronger code. And code I am more comfortable playing with.
You develop a trust in your tests, you know that if you mess something up (and you will), your tests will save you from going on after a mistake.
All in all, writing bugs has been a really positive experience that is leading me towards writing more code in full TDD mode in future.


Search





