Me and TDD
OK, so I'm looking into Test Driven Development (TDD).
Now, I've looked into working with it before within the PHP environment I use daily, but sometimes feel a bit overwhelmed by it all.
Every time I read up about it, I always get a different slant on things, and always learn something different or new from the time before, and feel I am getting to grips with the basic principles now.
The big question is whether to start from scratch or attempt to write tests for the existing codebases I have.
I have a personal codebase, albeit pretty dated, and then there are the (many) styles and codebases used at work for me to choose from. Part of the dilema is if I use any work code, I can't post it online or use it in my own work, although, to be honest, when work finishes, usually the last thing I want to do is come home and be glued to the laptop writing code. So that explains why I haven't made much progress over the past 3 years, and from time to time dip into blog articles and posts on TDD and Unit Testing.
Whether to use PHPUnit or Simpletest, whether to use a framework or not, and if I do use a framework, most of these have testing classes and modules integrated with them.
Along with beginning to look into TDD, a lot of the examples I am finding at for calculator and string classes, and very specific to testing the logic of these classes. When I think about applying these to the monolithic grouping of php files and classes that comprise bespoke and custom built ecommerce and cms systems, I suddenly become overwhelmed by the sheer amount of code I'm going to have to write. I mean, OK, I can write a unit test to verify an add() method works correctly and returns all the expected results given this input and that input, and throws exceptions or whatever. But what about scaling that up to handle items with stock levels, sizes and prices that can all change, mixed in with a checkout or buying process, and whether an order was successfully completed. Including discounts and shipping costs and members being logged in and all sorts - it just blows my mind trying to wrap all that up in tests.
I guess the key is to do it little bits at a time. Focus on possibly a member, then items, and the process of building basket, then the ordering process, then the checkout and confirm stages. Tying that all in with a database, and trying not to make too drastic a change that I may as well have rewritten it from scratch isn't easy.
So, it continues, my research into Unit Testing and TDD, and Acceptance Testing and ATDD. I am leaning towards PHPUnit, but when I start to think about Mocks and Stubs to isolate the tests, I feel I'm going to end up writing so so much more code trying to refactor my existing codebase, that I keep leaning towards a re-write!
And why I don't just do it... time I guess, when customers need a feature, they want it now, and they want to pay for that feature, not me going back and rewriting the existing system.
I would love to write more posts about my journey into actually beginning to follow TDD a lot more strictly, but I don't think that will happen today. Although, it might!
Comments welcome :)
Now, I've looked into working with it before within the PHP environment I use daily, but sometimes feel a bit overwhelmed by it all.
Every time I read up about it, I always get a different slant on things, and always learn something different or new from the time before, and feel I am getting to grips with the basic principles now.
The big question is whether to start from scratch or attempt to write tests for the existing codebases I have.
I have a personal codebase, albeit pretty dated, and then there are the (many) styles and codebases used at work for me to choose from. Part of the dilema is if I use any work code, I can't post it online or use it in my own work, although, to be honest, when work finishes, usually the last thing I want to do is come home and be glued to the laptop writing code. So that explains why I haven't made much progress over the past 3 years, and from time to time dip into blog articles and posts on TDD and Unit Testing.
Whether to use PHPUnit or Simpletest, whether to use a framework or not, and if I do use a framework, most of these have testing classes and modules integrated with them.
Along with beginning to look into TDD, a lot of the examples I am finding at for calculator and string classes, and very specific to testing the logic of these classes. When I think about applying these to the monolithic grouping of php files and classes that comprise bespoke and custom built ecommerce and cms systems, I suddenly become overwhelmed by the sheer amount of code I'm going to have to write. I mean, OK, I can write a unit test to verify an add() method works correctly and returns all the expected results given this input and that input, and throws exceptions or whatever. But what about scaling that up to handle items with stock levels, sizes and prices that can all change, mixed in with a checkout or buying process, and whether an order was successfully completed. Including discounts and shipping costs and members being logged in and all sorts - it just blows my mind trying to wrap all that up in tests.
I guess the key is to do it little bits at a time. Focus on possibly a member, then items, and the process of building basket, then the ordering process, then the checkout and confirm stages. Tying that all in with a database, and trying not to make too drastic a change that I may as well have rewritten it from scratch isn't easy.
So, it continues, my research into Unit Testing and TDD, and Acceptance Testing and ATDD. I am leaning towards PHPUnit, but when I start to think about Mocks and Stubs to isolate the tests, I feel I'm going to end up writing so so much more code trying to refactor my existing codebase, that I keep leaning towards a re-write!
And why I don't just do it... time I guess, when customers need a feature, they want it now, and they want to pay for that feature, not me going back and rewriting the existing system.
I would love to write more posts about my journey into actually beginning to follow TDD a lot more strictly, but I don't think that will happen today. Although, it might!
Comments welcome :)
Comments
Post a Comment