This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Test Driven Development  and UML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Test Driven Development  and UML" Watch "Test Driven Development  and UML" New topic
Author

Test Driven Development and UML

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Does UML modelling normally happen before or during Test Driven Development ?
Would the path to follow be :
Good OO Design with UML notation of that Design ----> Test ----> Code.
OR
Test ----> Good OO Design with UML notation of that Design ----> Code.

regards
[ September 10, 2003: Message edited by: HS Thomas ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

UML->CODE->TEST


Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Or...
1) Write a test
2) Draw UML (design/refactor a solution)
3) Write code
4) Run test
5) Loop 2-4 until test is passed and you can start over from 1


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Pradeep Bhat:
UML->CODE->TEST

Well, that's certainly *not* Test Driven Development! In TDD, both the code and the design are driven by writing unit tests. It's also called Test-First Development.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404

1) Write a test
2) Draw UML (design/refactor a solution)
3) Write code
4) Run test
5) Loop 2-4 until test is passed and you can start over from 1

Can practices in writing the test guide you towards Good OO ?
regards
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Can practices in writing the test guide you towards Good OO?

Writing the test first helps achieving a good design by telling you how the client code wants to access the not-yet-implemented functionality. On the other hand, the test-first thinking often drives your implementation towards a more test-friendly, clear structure.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

http://www.amazon.com/exec/obidos/tg/detail/-/0321146530/ref=pm_dp_ln_b_6/002-4811637-1947201?v=glance&s=books&vi=reviews
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

http://www.coderanch.com/t/98351/patterns/TDD-starting-OO
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by HS Thomas:
Does UML modelling normally happen before or during Test Driven Development?

Actually, both.
Imagine an Iteration Planning Meeting:
A: OK, I will do Foo this iteration.
C: How long do you think it will take?
A: I guess I will have to implement a Fabulator to put into the Zork. It's a little bit tricky...
B: Why don't you just tork the Zork with the existing Tofbul?
A: ???
B: (goes to the whiteboard and sketches a collaboration diagram) See, the Zork already has an Uglo (scribble) so if you just get the Tofbul from the Brot (scribble), and tork it...?
A: Of course - why didn't I think of it. Make that a 1, then...
Now imagine some days later, A starts to pair with D:
D: OK, I still remember the diagram from B roughly, so let's just start!
A: Wait a moment - do we really have to zork the Zork?
D: I am not sure - let's start writing a test and see what happens.
[a few tests later]
D: Ah, I think no I see what you mean. (gets pen and paper) Let's see - we currently have this (scribble), so if we just let the Uglo know about the Brot (scribble)...?
A: Yes, that is what I was thinking! Let's see how it works out.
Did that help?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Lasse Koskela:

Writing the test first helps achieving a good design by telling you how the client code wants to access the not-yet-implemented functionality. On the other hand, the test-first thinking often drives your implementation towards a more test-friendly, clear structure.

And test-friendly actually means well decoupled - a tightly coupled systems is horribly hard to unit test!
HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404
Did that help?

jIyaj . majQa' . - I understand. Well done!
(HTML now includes a Klingon LANG code,prefixed by x- to indicate it's an experimental language.)
That aside, it is a good example.
At the Iteration planning meeting , you have allocated tasks, scheduled the task , first cut design in UML.
D and A Pair programming days later, D has agilely obtained the UML diagram from B. I suspect D has already started thinking about the tests because he pre-empts A with his comment to start testing first before they waste any time re-modelling the UML.
A lets him get on with it because he knows D likes to code. D realises A's doubts (not only is he a fast coder he is a fast learner) and let's A take control again.
Done and dusted in a matter of minutes.
Cool example, Illja.
regards
[ September 10, 2003: Message edited by: HS Thomas ]
Robert Martin
Author
Ranch Hand

Joined: Jul 02, 2003
Posts: 76
UML and TDD are both tools. They have no implied order. I often start with tests, and then break out and do some UML. Sometimes I don't do any UML at all. Other times I will scratch some UML before writing tests. It all depends upon my mood, and my understanding (or lack thereof) of the system I am writing.
Don't look for good software engineering practices in the order of those practices. Look for it in the intelligent use of those practices. Like the song said: "Every hand is a winner, and every hand a loser." So it is with practices. It's not in the hand, it in the way the hand is played.


---<br />Uncle Bob.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

I agree that there is no set order. We have used UML for the high level/architectual design. This sets the API. Then, I would use TDD to actually develop the functionality.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
 
subject: Test Driven Development and UML
 
Similar Threads
In a software project- Is Agile approach dependent on the technologies used in the project?
Recommendation for Learning OO Design
UML for Java Programmers
Enterprise Java with UML
Tale of a test driven challenged programmer.