Test driven development

Can anyone explain to me what is the best way to move forward in an application?
I think Test driven development to be the best and used by everyone at thoughtbot and I believe you try to make sure your tests are what drives your implementation.

But then when does the design part come into the picture? Is it during the refactoring part for example the database design. ?

And also when you have a client who wishes to see a prototype as soon as possible do you still use TDD ?

What if your are trying to develop an app but have no clue how it is gonna be implemented, so do you still use TDD in such a case or prefer doing a test later implementation first?

Design drives what we are building, it never “comes into the picture” it is there from the beginning and is constantly iterated upon and changed, just like the code is.

We always do TDD, being experienced practitioners of it, it doesn’t really slow us down for most development. When it does slow down up-front development, its worth the tradeoff in the time it will save later.

You used the word ‘prototype’. We very rarely, if ever build prototypes because they are built with a ‘throwaway’ mentality, and then are very rarely actually thrown away. Instead, we focus on shipping useable software quickly that can be rapidly changed, but that provides the basis of an actual production system.

If you don’t know how something is going to be implemented you might not understand what you are actually supposed to be building, and therefore you should not be coding yet. Instead, go back and do more wire framing or discussing to figure out what you are actually building.

Alternatively, you might not understand how to architect the code of the system. Doing TDD will drive you to good code/good architecture, because bad code is hard to test.

Finally, you really may not know enough about how a particular library is going to work, or just how to write something. In this case, it is ok to write some untested code to figure out the stuff you don’t know. This is called a spike. Once you’ve got it figured out and you understand, throw the spike out (yes, really) and start over doing TDD.

All of the above is where you’ll end up when you are experienced with TDD. You may not be there now. Tests are better than no tests, so if you are getting started with TDD and its hard, and it’s easier right now to write some tests after you write the code, it’s not the end of the world, it’s better than nothing. However, it’s important to understand how you want to be getting better than that, and hopefully the next time you start writing code, you’ll be able to do even more TDD as you are more comfortable with the flow and the tools.

Thanks,
-Chad

4 Likes

@cpytel I just have tech specs for the prototype. Can I write as many spec examples as possible and think of the refactoring later? I mean one of the spec is

A user first creates an account and then either first creates a team and then invites friends or first joins a challenge and then invites friends to create a team. 

Can I write code just to make this pass? Can you point me to to some resource on the net that will help me approach such types of problems. ?

This is what I was going through right now.

require 'spec_helper'

feature "Team formation" do
	scenario "User creates a team by himself" do
		visit root_path 
    click_link "Sign up"
    fill_in "Email",with: "ankothari@gmail.com"
    fill_in "User name",with: "Ankur Kothari"
    fill_in "Password",with: "aakk3322"
    click_button "Create Account"
    click_link "Create Team"
    fill_in "Name",with: "GetFitGo"
    click_button "Create Team"
    expect(page).to have_content "Team GetFitGo created. Now pick a challenge first or invite friends."
    expect(page).to have_link "Invite Friends"
    expect(page).to have_link "Choose Challenges"
	end

	scenario "User first clicks on a challenge, invites friends and then forms a team" do
		
	end
end

and this is what I wrote to just make it pass.

Team GetFitGo created. Now pick a challenge first or invite friends.
<%= link_to "Invite Friends", "#"%>
<%= link_to "Choose Challenges", challenges_path %>

What do I do now?

The advice I have was for not building prototypes. But it sounds like you’re building one. If you really are, then my advice will be different.

So, are you building a prototype? As in, this is just to show the flow and how things will work, but it won’t be functional and it will be completely thrown away when it’s done?

No it isnt going to be thrown away. We need this product to take user feedback and will then based on that would be doing the further development. You can say it to be the version 0.0.1.