Test-Driven-Developement and me

So I’ve recently finished the book “Growing Object-Oriented Software Guided by Tests” which in general is a good book except for the major reservation I have for it – it talks about Java, and trying to implement what they say in Javascript isn’t really 1:1, especially due to the lack of contracts. In general I don’t like interfaces and contracts as you can’t tell which implementation was actually used, while Javascript requires a different state-of-mind which covers this aspect: since I don’t know which JS file was loaded or not – there is no contract, I just hope the right library was there to catch the call. I know not knowing if the call was answered sounds worse than not knowing who answered it, but in Javascript it makes a lot of sense and the dynamics is one of the language strongest features.

But I did learn some great things from this book, such as “Domain separation” – each Class (in my case it’s the xxProcess.js files) should handle one domain and not care about anything else – it shouldn’t care what DB will be used or how the output will be used – only what’s the input and what’s the proper output. It actually was like this before where the only change I made in the code in this regard was to extract “Comments” function to a new process file.

Another thing was to have descriptive function names for test so you’d know exactly what this test is running. I had a testProcess before which I didn’t really use. I’ve added Qunit in and created a simple mechanism to run the tests from the console. I removed the testProcess and maybe I’ll add it again in the future.

I now came the big dilemma. I had tons of code to test-unit and it’s sisyphus, especially as I know that i’s working on all cases I might write a test. Test should be something that might fail and break something else down the chain, but as I mention, javascript don’t really have a chain. On the other side, I have a DB integrity issue. It goes like this – in order to do some developing on my local machine, I externally-edited the DB and changed the ownership on some comments and rewired them to different posts. A comment have actually two parents – the topic and the parent-comment, but because of my manual edits, I have some errors there now. Once I realised that, I updated the code so it would log an error and ignore that comment. I’m not too concerned about this scenario because something like this shouldn’t happen in the production. or should it? how can I make sure that another unforeseen event won’t take place? what test exactly should write?

So it came down to this. Yes, I wrote the testing-platform which works great. Yes, I wrote some tests into it. Yes, I know I should use it from now on. But then, for the next major development, I didn’t use it – I didn’t write any test before or after making a huge change and I’m quite sure my new code works great, Because I fiddled with it and any test I might have written – I also checked it myself. Took me a lot less time, I’m sure. This is something that actually bothered me in the book – how much time do they spend writing the test? yes, writing test is important, I’m not saying it doesn’t – but the longer you spend writing test – the more probable you’ll have bugs in the test-code and you’ll spend hours to fix your tests instead of just continuing to write the code.

So yes, I promise that from now, I’ll try writing more tests as part of the design process. While writing this I’m fully aware that I’m lying, which is kinda sad.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: