Which approach is recommended: TDD&DBB first or after?

19 views
Skip to first unread message

Askar

unread,
Jul 23, 2015, 8:20:30 PM7/23/15
to rspec
Hello!

Nowadays I'm reading Rails 4 in Action book and I like it very much.

They're using TDD&BDD first, then building the rest as test goes.

I wonder which approach is better: Build the basics of the app without testing, confirm that it works visually and then making TDD & BDD?

Or start straight away from TDD & BDD.

In the book, rspec, factorygirls and capybara used.

Jon Rowe

unread,
Jul 23, 2015, 8:25:36 PM7/23/15
to rs...@googlegroups.com
If you are attempting to do Test Driven Development (TDD) or Behaviour Driven Development (BDD) then you should write the tests first, thats part of these approaches to development (hence the driven part of the acronym).

Debating wether a TDD/BDD approach versus a ‘test afterward’ approach is better is a big discussion but there are benefits to each, I will say that you are more likely to actually write tests if you write them before you write the code however.

Regards
Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/771c357b-5361-439e-83d1-51e976d0db3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Chaffee

unread,
Jul 24, 2015, 11:48:49 AM7/24/15
to rs...@googlegroups.com
This is a great question as the TDD orthodoxy was developed in a land without HTML or CSS and often skips over the issues of testability and brittleness and "could this really break in a meaningful way?"

You should definitely test-drive your models and controllers. But should you test-drive your views? Maybe if there's logic in there. But if there's logic in the views, maybe that logic should move to the controllers where it's easier to test. Then the controllers can either select which view to render, or pass on variables to the view to tell it what to do. 

That's because testing HTML&CSS tends to be very brittle. You can make a non-functional change (like changing an H2 to an H3) and break your whole test suite. Ugh. That pain encourages you to just ignore or remove the tests, so what's the use?

btw your first option:"Build the basics of the app without testing, confirm that it works visually" is what XP calls a "spike". After you do that, you're supposed to throw it away and start from scratch with tests. (And yeah, maybe copy some code over from your spike, but always with a red test first.)

 -A
--

Askar

unread,
Jul 26, 2015, 11:32:11 PM7/26/15
to rspec, ale...@gmail.com
Thanks for replies, Jon and Alex!

(I've just accidentally noticed the replies, I thought I'll get notifications. It seems I forgot to subscribe)

Currently, I'm in the middle of the Rails 4 in Action book and noticed it's really time-consuming to write tests, but I understand, this will make my life easier in the long run of the application maintenance and future development.

Regards,
Askar
Reply all
Reply to author
Forward
0 new messages