TDD or not TDD? This isn’t the question.

Instead of reply to these reasons:

http://www.phpclasses.org/blog/post/237-7-Reasons-Why-TDD-Failed-to-become-Mainstream.html

I prefer to find what make testing hard: mock object, the missing part!

All these arguments seems to fail to understand that TDD is not just testing, it is to guarantee SOLID principle of object oriented design

Liskov substitution, Interface segretation, Dependency inversion, and also single responsibility and open/close principles are very explicit if you want to do TDD in a simple way: write mock object and separate everything

Working with Javascript NodeJS (but also with php and lambda expressions) write a mock object does not require a specific library or tool, just write the object in JSON format and pass it to the object to test.

Say you want to test an object an know if it correctly insert a row in the db:

var dbMock = {
   inserted:false,
   insertedData: '';
   insert: function(object) {
     this.insertedData = object.data;
     this.inserted = true;
   },
   lookup: function(id) {
     return {id:id,field1: 'example content'};
   }
};

var objectToTest = new ClassType(dbMock);

objectToTest.DoSomeTask(parameters);
expect.equals(dbMock.inserted,true);
expect.equals(dbMock.insertedData,'my expectation for data');

and pass it to the object to test.

That force you to write clean code. Just that.

I personally prefer jasmine-node.

The same apply to PHP, trust me!


Posted

in

,

by

Tags: