Skip to content

Video tutorial: Test Driven Development in practice

September 18, 2008 by Przemysław Bielicki

In this nine minute tutorial I'm presenting TDD way of developing software i.e. start from writing the test.

Many people often say that you should start from implementing at least interface and then start testing. In this tutorial I'm showing how easy it is to start writing unit test with nothing (not even an interface) i.e. only having the requirements. After couple of minutes I've got an interface, a working implementation and a full test suite.

This is what Test Driven Development is all about - software should be developed this way IMO. Sources for this tutorial can be found here
The voice volume is quite low so I recommend using headphones and increasing sound volume a bit while watching this video


I hope you like it. If you have any comments, please share your opinions here.

About the Author: Przemysław graduated from Gdańsk University of Technology in 2004 having specialized in Distributed Information Systems. He worked in Lufthansa Systems, Intel Corporation in the past where he developed complex IT solutions in many Java-related technologies. In professional life he is a real Java expert holding couple of Sun Java certificates (Programmer, Developer, Web Developer) and Certified Scrum Master, of course.

Przemysław is a regular contributor to AgileSoftwareDevelopment.com and the author of "From Java to Java EE" blog. He now works as a Software Craftsman in an international company that is the leading Global Distribution System (GDS) and the biggest processor of travel bookings in the world. Contact Przemysław

Comments

Great Screencast

September 18, 2008 by Patrick Baumgartner (not verified), 5 years 45 weeks ago
Comment id: 1853

Hi,

great Screencast! You show in a simple way how to do TDD without any big theories.
Is it nessecary to name the test method "testSomething"? In my opinion, you annotate the test method which should be enough, or do you think it's just for a better unsterstanding to use the same name as we used in JUnit 3.x ?

Greez

No, it is not necessary to

September 18, 2008 by pbielicki, 5 years 45 weeks ago
Comment id: 1854

No, it is not necessary to name the test method "testSomething" - it is just my old habit from JUnit 3.x. I think it's for better understanding and distinguishing the real test methods in JUnit classes.

As far as I know @Test intent was to get rid of "testSomething" convention but I'm still sticking to it. Why? Give me more meaningful method name for testing Add operation - if you find any I will use it :)

Cheers!

Refactoring after the green bar

September 18, 2008 by Artem, 5 years 45 weeks ago
Comment id: 1855

Very illustrative screencast indeed. I would like to note one thing, though. starting at the 8 min point, you extract a method from already working function (i.e. refactor), while been in the red state.

In TDD all the refactoring is supposed to happen during the green state only. In this small example and due to the intelligent ExtractMethod wizard it didn't matter much, but in real projects when I was still learning TDD several times I was able to mess up the code, when I was trying to refactor during the creation of new stuff. I find that the habit of separating the TDD phases clearly usually pays off. Especially if you are working in a less automated environment, than a typical Java programmer (my TDD background is from embedded C++ mainly).

My 2 cents

September 18, 2008 by hmoeller, 5 years 45 weeks ago
Comment id: 1856

I liked watching your video as well. Especially the heavy use of IDE convenience functionality made the process transparent and fluent.

As to the naming convention: Somebody lately suggested to name them "should". Those names can become pretty long, but they are something like a short documentation on what is under test. You won't use those names elseware anyway.

@Artem

You're right concerning the refactoring steps. But consider all those other convenience functions used. You expect them to do the right thing. When using such a sophisticated IDE, the borders between refactoring as a process step and using "enhanced editor functions" is fuzzy, isn't it?

"Should" would actually fit

September 18, 2008 by pbielicki, 5 years 45 weeks ago
Comment id: 1857

"Should" would actually fit my naming convention (maybe even better) e.g. shouldAddAndThrowOverflowException, shouldReturnManyEntries, etc. (instead of testReturnManyEntries). "Should" makes it more human-language which makes it easier to understand and tests are supposed to be the design of your system - that works perfectly.

Cool! Thanks for your comment.

On the other hand, if You

September 18, 2008 by krzysieq (not verified), 5 years 45 weeks ago
Comment id: 1858

On the other hand, if You name a method "shouldAdd", then it implies to someone new to Your code, that it's this particular method that should actually Add (kind-of wishful thinking approach), while in fact it merely tests the functionality of another method defined elsewhere. IMHO, testAdd will ever remain the most straightforward way of naming test methods. After all, everyone who has completed at least a couple of first classes of primary school knows, what a test is.

Cheers,
Chris

TestAdd method

September 18, 2008 by Sim (not verified), 5 years 45 weeks ago
Comment id: 1859

Should the test methods only test one case to have smaller test methods vs test all cases in one method?

example:
TestAddUnderflow(){
// test add underflow
}

TestAddOverflow(){
// test the add overflow
}

TestAdd{
// Test normal implementation
}

Sim

Re: TestAdd method

September 18, 2008 by pbielicki, 5 years 45 weeks ago
Comment id: 1860

It is a good practice to do this like you described (video doesn't show this due to length constraints). You can create as many test cases as you can imagine in one method and then refactor the unit test class. Remember that test classes are first-class citizens so they should also be refactored, nicely coded, blah blah blah...

I just attached source code

September 18, 2008 by pbielicki, 5 years 45 weeks ago
Comment id: 1861

I just attached source code (+ Eclipse projects files) here: http://agilesoftwaredevelopment.com/files/tdd-tutorial.zip

Detour

October 3, 2008 by me (not verified), 5 years 43 weeks ago
Comment id: 1890

If you are only testing requirements you were given, you are going to miss something. I see no real benefit in TDD as you are just taking longer to arrive at the same point. You still have to add test cases to test the code that you wrote that doesn’t necessarily test the given requirement.

TDD is just another way to do things, nothing more.

No, you are not testing only

October 3, 2008 by pbielicki, 5 years 43 weeks ago
Comment id: 1891

No, you are not testing only given requirements. While testing and implementing your code you discover many things like exceptions, extreme values, etc. Doing this according to TDD you save your time because you end up with full test and implementation at once - it's transparent for you. And even if you miss something that's OK!!! You can add as many tests as you want later - remember that tests are to prevent bugs not to discover them.

Thanks for you comment.

Awesome

January 7, 2009 by Farhan Thawar (not verified), 5 years 29 weeks ago
Comment id: 2153

Thank you thank you thank you for this.... just sent this to my team :)

brillliant

February 19, 2009 by Anonymous (not verified), 5 years 23 weeks ago
Comment id: 2258

Very clearly put - just what I needed to crsytalise my understanding of TDD. Love how you use eclipse to generate the code as you go along!!!

HotKeys

May 6, 2009 by Ryan (not verified), 5 years 12 weeks ago
Comment id: 2518

Great video... what are the hotkeys you are using to pull up the create class... create method menus?

Re: HotKeys

May 6, 2009 by pbielicki, 5 years 12 weeks ago
Comment id: 2519

Ctrl + 1 - quick fix
Ctrl + T - find all implementation of given interface (shows type hierarchy)

I hope that helps :)

Ctrl + 1 was what I was

May 7, 2009 by Ryan (not verified), 5 years 12 weeks ago
Comment id: 2523

Ctrl + 1 was what I was looking for! Makes TDD 10x easier... in .Net/Respharper use Alt - Enter. Thanks!

evden eve nakliyat

May 25, 2009 by evden eve nakliyat (not verified), 5 years 9 weeks ago
Comment id: 2611

thanks. wery good. evden eve nakliyat

evden eve nakliyat

May 25, 2009 by evden eve nakliyat (not verified), 5 years 9 weeks ago
Comment id: 2612

thanks. wery good. evden eve nakliyat

Great

June 4, 2009 by Tariq (not verified), 5 years 8 weeks ago
Comment id: 2661

Great intro to TDD, and IDE features :)

Thanks!

Tariq

Great overview

June 25, 2009 by Chris (not verified), 5 years 5 weeks ago
Comment id: 2771

Watching the video is a whole lot easier to understand this concept than just reading a description. Thanks!

Thank you . Have you written

December 15, 2009 by yakub (not verified), 4 years 32 weeks ago
Comment id: 4407

Thank you . Have you written any book on TDD ??????

Thank you . Have you written

May 17, 2010 by Aşk Büyüsü (not verified), 4 years 10 weeks ago
Comment id: 6659

Thank you . Have you written any book on TDD ??????

I will forward this article

February 22, 2012 by jieler (not verified), 2 years 22 weeks ago
Comment id: 20986

I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!oil expellers

graphic design

March 19, 2012 by graphic design (not verified), 2 years 19 weeks ago
Comment id: 21428

quite impressive article it will be very useful information you put a very nice subject here.
graphic design

This is a good site that

March 27, 2012 by srer (not verified), 2 years 17 weeks ago
Comment id: 21516

This is a good site that dedicated to the education world. They try to make all the students in all over the world get what they need. A lot of school need to get help from the data that they have.Flour Mill Machine

In the vaporizer reviews

May 21, 2012 by Sam O'neal (not verified), 2 years 10 weeks ago
Comment id: 22279

In the vaporizer reviews you will learn about different types of the Volcano Vaporizers and will know how to choose the best for yourself.

Hi are using Wordpress for

May 26, 2012 by Grazyna Braye (not verified), 2 years 9 weeks ago
Comment id: 22563

Hi are using Wordpress for your site platform? I'm new to the blog world but I'm trying to get started and create my own. Do you require any coding expertise to make your own blog? Any help would be really appreciated! Grazyna Braye

I am really impressed by

June 4, 2012 by wandybrad (not verified), 2 years 8 weeks ago
Comment id: 22763

I am really impressed by reading this article. Interesting post and I really like your take on the issue. I now have a clear idea on what this matter is all about. Thank you so much.
Custom Home Builder Austin TX

awesome

June 15, 2012 by Austin Wedding DJ (not verified), 2 years 6 weeks ago
Comment id: 22926

Excellent article.Its really a good article. It gives me lots of pleasure and interest

Rale galvanising

June 20, 2012 by jgurma (not verified), 2 years 5 weeks ago
Comment id: 22971

Rale galvanising penalization. Transactions has been handwritten in hit overnice enounce. I tap accruement this palatalised of becalm. Thanks for coitus gaolbreak noesis.
astrology software from world of wisdom

, basically just enough code

June 26, 2012 by rockskhan (not verified), 2 years 4 weeks ago
Comment id: 23055

, basically just enough code to fail. Next you run your tests, often the complete test suite although for sake of speed you may decide to run only a subset, to ensure that the new test does in fact fail. You then update your functional code to make it pass the new tests. The fourth step is to run your tests again. If they fail you need to update your functional code and retest. Once the tests pass the next step is to start over
jocuri logice zuma

awesome

July 18, 2012 by emon2010 (not verified), 2 years 1 week ago
Comment id: 23415

Very interesting post... something really informative... I wish to read something like this again... we keep coming back to your blog..
South Congress Home Listings

nice comment

July 19, 2012 by Kaushal (not verified), 2 years 1 week ago
Comment id: 23444

Interesting post and thanks for sharing. Some things in here I have not thought about before.Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.Keep blogging
Buy One Way Backlinks

Comments

July 20, 2012 by Kaushal (not verified), 2 years 1 week ago
Comment id: 23452

Super bonne continuation blog I think they must have to fighting hard in the last match because it's really deciding them to pass to round of last 16. Godd luck for them.
Thank you. We have to try this.
High Pagerank Link

achoice-insurance.com

July 23, 2012 by mudassar (not verified), 2 years 1 week ago
Comment id: 23482

achoice-insurance.com Thanks for sharing this useful information! Hope that you will continue with

best telefonkatalogen.biz

July 31, 2012 by best telefonkatalogen.biz (not verified), 1 year 52 weeks ago
Comment id: 23595

I admire what you have carried out right here. I such as the component where you say you're doing this to give back again but I would presume by all the feedback that this is operating for you as well.

awesome

August 2, 2012 by 555 Condos (not verified), 1 year 51 weeks ago
Comment id: 23628

yes thats a grate idea i will try this . i will reply you after try keep working good job thanks"

hi

August 2, 2012 by hani (not verified), 1 year 51 weeks ago
Comment id: 23640

loans
Donors are not the solution, while they grab headlines regarding their development work, government spending remains the majority by an overwhelming margin.

hi

August 24, 2012 by nisha (not verified), 1 year 48 weeks ago
Comment id: 23651

casino spelen
It's used for security and safety of the website. So they can protect their site from bots.

awesome

September 3, 2012 by emon2010 (not verified), 1 year 47 weeks ago
Comment id: 23713

Surfing the net for some information I came across your blog. I am impressed by the information you have on this.
Tvorba webových stránek

awesome

September 9, 2012 by emon2010 (not verified), 1 year 46 weeks ago
Comment id: 23769

Personally i think strongly regarding it and love learning much more about this topic
SEO

I admire what you have

September 10, 2012 by ali (not verified), 1 year 46 weeks ago
Comment id: 23787

I admire what you have carried out right here. I such as the part where you say 640-553 exam you are doing this to give back again but I would presume by all the feedback640-553 practice tests that this is operating for you as well.

This site is very informative

September 10, 2012 by kashif (not verified), 1 year 46 weeks ago
Comment id: 23788

This site is very informative attractive and very beautifully arranged.Business is a trade of providing goods and services including financial, commercial and industrial types.raid recovery

You own a very interesting

September 13, 2012 by raqueljohn87 (not verified), 1 year 45 weeks ago
Comment id: 23847

You own a very interesting blog covering lots of topics I am interested as well.Just bookmarked your blog to continue reading in the next days' Please continue your marvelous work.
Cell phone spy

Its a great pleasure reading

September 17, 2012 by diya (not verified), 1 year 45 weeks ago
Comment id: 23909

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
essay

Very illustrative screencast

October 5, 2012 by Anonymous (not verified), 1 year 42 weeks ago
Comment id: 24215

Very illustrative screencast indeed. I would like to note one thing, though. starting at the 8 min point, you extract a method from already working function (i.e. refactor), while been in the red state. Buy Facebook Fans

Personally i think strongly

October 6, 2012 by turismro (not verified), 1 year 42 weeks ago
Comment id: 24248

Personally i think strongly regarding it and love learning much more about this topic Cazare Busteni

Hmm it looks like your site

October 24, 2012 by Anonymous (not verified), 1 year 39 weeks ago
Comment id: 24273

Hmm it looks like your site ate my first comment (it was super long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog.web 2.0 marketing

Hmm it looks like your site

October 31, 2012 by Anonymous (not verified), 1 year 38 weeks ago
Comment id: 24325

Hmm it looks like your site ate my first comment (it was super long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying.nettoyage de vitres saint-eustache

This is a great inspiring

November 6, 2012 by nobel (not verified), 1 year 38 weeks ago
Comment id: 24494

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up.
translate russian to english

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Best of AgileSoftwareDevelopment.com