In Hong Kong, as a fast moving city, “urgent” is one of the most common requirement from the clients. They require the most “cost-effective” way to implement systems and with a marginal price. For these low budget (but urgent) projects, some of the local software houses would simply deliver a “just-to-requirement” and “not-well-tested” solution to the client — the result is poor client satisfaction.

What we believe is — quality software is the base of the success of one software company. Therefore, we strictly adopt the agile development process and BDD is one of the testing approach we used.

In order to perform effective testing across increasing complex application, we adopted BDD in our projects. Some of the developers are lazy to write test cases throughout the development as they found that some test cases are meaningless to be written. When the application complexity increases, testing would be the harshest part of the development process.

Here is an example of “meaningless” test case:

class UserTest < Test::Unit::TestCase
def test_create
user = User.create(:some => ‘params’)
assert user.save
end
end

In this kind of test case which we regard as “meaningless” because it tests on the framework but not our own code. What we need is an effective testing across our codes.

Some Background

What is BDD? Behaviour Driven Development is an Agile development process that comprises aspects of Acceptance Test Driven Planning, Domain Driven Design and Test Driven Development.

RSpec is a BDD tool aimed at TDD in the context of BDD. And as our application is mainly built on Ruby on Rails, what we need is RSpec and RSpec on Rails plugins for our applications.

For more details on BDD: http://en.wikipedia.org/wiki/Behavior_driven_development

And more details for RSpec: http://rspec.info/

To install the plugin of RSpec and RSpec on Rails, what we need is to go here

http://github.com/dchelimsky/rspec-rails/wikis/home

but for the latest version (v 1.1.4) it only offers git repos to install, and we get some time to install the git into our system (as we have sticked to svn for long)……

We uses RSpec for testing as it is somehow more realistic to test the application on the “behaviour” instead of unit. Here is a piece of test case we wrote to illustrate the ellegance of the BDD:

describe Bid do
it ’should create reference id automatically’ do
@bid = Bid.new
@bid.reference_id.should_not be_nil
end
end

It is a test case to test whether the ‘reference_id’ would be created automatically when we ‘new’ the Bid object. We are testing on the application behaviour rather than testing whether we can create the object.

Here is the result, printing in a nice specdoc format:

$ spec spec/models/bid_spec.rb –format specdoc
Bid
- should create reference id automatically
Finished in 0.138937 seconds
1 example, 0 failures

btw, git is the next part we should spend time to explore, probaby after we finish some important client’s projects….