Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 18 - Pages: 2   [ 1 2 | Next ]
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Manning releases a must have book: Test Driven

At 9:22 AM on Oct 3, 2007, Meera Subbarao wrote:

Test-Driven Development, TDD as it is commonly called, is an evolutionary software development technique that involves first writing a test case and then implementing only the code necessary to pass the test. TDD gives rapid feedback. Its usually a 3 step approach, write test, write the code, and finally refactor.

The book is written by Lasse Koskela , a methodology specialist at Reaktor Innovations in Finland, has coached dozens of teams in agile methods and practices such as test-driven development.

Here is a brief description of the book from Manning's web site:
In test-driven development, you first write an executable test of what your application code must do. Only then do you write the code itself and, with the test spurring you on, improve your design. In acceptance test-driven development (ATDD), you use the same technique to implement product features, benefiting from iterative development, rapid feedback cycles, and better-defined requirements. TDD and its supporting tools and techniques lead to better software faster.

Test Driven brings under one cover practical TDD techniques distilled from several years of community experience. With examples in Java and the Java EE environment, it explores both the techniques and the mindset of TDD and ATDD. It uses carefully chosen examples to illustrate TDD tools and design patterns, not in the abstract but concretely in the context of the technologies you face at work. It is accessible to TDD beginners, and it offers effective and less-well-known techniques to older TDD hands.

And to know what's inside the book:

* Hands-on examples of how to test-drive Java code
* How to avoid common TDD adoption pitfalls
* ATDD development and the Fit framework
* How to test Java EE components Servlets, JSPs, and Spring Controllers
* How to handle tough issues like multithreaded programs and data-access code

If you would like to get more details about this book, here is the link: http://www.manning.com/koskela/

Lasse Koskela takes a few moments to sit down with Javalobby and talk about his experience of writing this exciting new book.

Q: Hi Lasse, could you tell us a bit about yourself, and where you work?
I'd be glad to do that, Meera. My journey in the software development industry began during the last IT bubble when I jumped ship from the online media business to work on the sexy web stuff. I first started programming simple database-driven web applications for a publishing company and soon joined a small new media company where I became the jack-of-all-trades for our two Java-based products. Back then I was spending way, way too much time in front of a computer but I was also learning a lot. Every day.

Around 2002 I started feeling a bit cramped with my little sandbox of the two Java-based products and decided to move on again. This time, I went for a big multinational consulting company, looking for opportunities to work on really big systems. Around the same time my interests started moving strongly from purely technical topics towards
the world of techniques, methods, and methodologies. Eventually I became the internal agile evangelist in a company that had experienced massive success with heavyweight processes.

Some three years later I was again looking for a change. I had basically failed in my attempt at turning the multinational consulting company's direction towards agile methods and decided to change my organization the other way. In the summer of 2005 I joined my current company, Reaktor Innovations, a small 80-man consulting powerhouse
based in Helsinki, Finland. We specialize in solving the most challenging problems our clients throw at us and we use agile methods all the way. We've recently started doing more and more coaching on agile methods and these days I spend most of my time doing just that--helping our clients' developers and product management get the most out of their time and investments.

And I'm loving it! I get to move back and forth between solving technical problems, solving organizational problems, training developers, being a developer, coaching team leads, and mentoring product managers. I'm truly lucky to be in this position.

Q: Why did you decide to write this book?
I decided to write this book because of envy. Let me explain. Back when I first started thinking about the book's contents, I realized that I was going to write the book that I would've killed for five or so years ago. Back then, I was trying to learn TDD basically on my own. Well, I had a great sounding board in Allan Halme, one of my colleagues at that time, but having this book would've made a big difference in how much time and effort it took to figure out the small stuff that makes a big difference. That was the last straw. I had no other choice but to make it happen!

Q: Is this your first book?
Yes, this is my first book. I've written articles before, for magazines as well as online, but I had no idea what it would be like.

Q: How easy or hard was it writing this book?
You've probably heard people say that writing a book is like giving birth? It's true. It took my almost three years to get it out!

There were a lot of surprises along the way. One of the hardest parts of the job was to write well. It was like a shell shock to find out how bad a writer I was back when I turned in the first draft chapters! Manning's editors did an amazing job in schooling me about the various techniques and nuances that make for a good text. I know for a fact
that the book wouldn't have been as good as it is if I didn't have such a fantastic staff to support me along the way.

The final finishing touches were a killer, too. I had no idea how much time and effort it would take to revise the manuscript based on reviews or how much time and effort it would take to create the index. The sheer amount of change that took place over these years was so huge that I think I wrote the book three times!

I have to admit, though, that I didn't really write the book for three years. There were several periods where I didn't work on the book for several months, focusing my energy on other stuff like work, learning, and having a personal life. Then I would pick up the manuscript again and work on a couple of chapters. Also, I was working full-time
throughout this project so that's already a big influence in how long it took in calendar time.

Q: How much time did you take to write this book?
As I said, the whole project took almost three years. To be more specific, two years and seven months. I started around February, 2005 and the final manuscript went to press in September, 2007. I didn't work on it all of that time, though, and I had long periods of zero productivity with regards to the manuscript so it's really difficult to give you a number. I once heard an estimate that writing a book takes 1,000 hours on average. That could very well be in the right ball park.

Q: When did you get the idea to write this book?
I actually got the idea from Manning. They asked if I'd be interested in writing something about TDD. I thought about it for a while, sketching a table of contents, and quite quickly came into the conclusion that I most certainly am interested and will write a book on TDD. That's the whole envy thing I mentioned before.

Q: Who is your target audience?
My target audience is developers. Mostly Java developers because I use Java for examples throughout but most all of the concepts I describe are equally well applicable to, for example, .NET development. It's just the APIs and language that are different. "Test Driven" is really such a comprehensive package that it has something for complete
TDD-newbies as well as for more experienced TDDers. Also, I'm quite confident that the text I've written about Acceptance Test Driven Development is valuable to almost any colleague whose looking into or is already doing Acceptance TDD.

Q: What specific technologies are you covering in this book?
I've tried to stay current with all technologies I've covered in the book. That means that all of the examples have been written in Java 5 and against a recent release of JUnit 4. Also, I've tried to pull in what I consider the most common open source frameworks such as Spring and Hibernate, as well as frameworks I consider the best kept secrets of the Java community, such as Apache Wicket.

Q: Do you show how to test EJB's(including 3.0) as well?
I most certainly do. In fact, we decided to make the chapter on test driving EJBs a bonus chapter available online from Manning's website (http://www.manning.com/koskela). Actually, often times it felt awkward to talk about testing EJB 3.0 components because it's gotten so much easier compared to the old EJB 2.x versions of the specification! Nevertheless, I talk about test driving session beans, testing for the container-component contracts, about dependency injection, faking the JNDI tree, and about testing the asynchronous stuff such as timers. It's not quite as straightforward as writing tests for plain old Java objects but it's certainly not as hard as people seem to think. I guess the pain of EJB 2 is still in our minds...

Q: What are the main things you learned while writing about TDD?
Wow. That's a tough question to answer. So much has happened during these years. Regarding TDD, I've certainly developed my sense of design as well as my concept of how TDD works best for me. I've also learned a lot about solving the kinds of technical problems I faced myself when I first started doing it.

Q: Now that you have written this book, If I can ask, what is the percentage of coverage you have in your code?
Coverage?

I'll have to check. You see, I'm not that much into measuring test coverage. To me it's more important that the tests I have are expressive and meaningful. The last project I checked the coverage for, it was well above 90%. I do get questioned a lot about
the magic 100% test coverage. I don't consider that a sensible "target" for Java code, though, because of some of the APIs we use. For example, I don't want to write a test for an exception that cannot happen in the context where I'm using the API and some people are just stubborn about throwing checked exceptions ;)

Q: What would you like to say to developers who say they don't have time to write tests or that their code is too complicated to write any tests?
I would suggest they stop writing code immediately. Otherwise they'll soon be too busy fixing bugs that they won't have time to check the new content on JavaLobby!

Do you have questions for Lasse or did we miss something in the interview? Post your questions here and he'll try to answer them for you!

Purchase and support Javalobby
1 . At 9:43 AM on Oct 3, 2007, Matthew Schmidt wrote:
  Click to reply to this thread Reply

Excellent interview and a question for Lasse

Hi Lasse. Thanks for taking the time to answer Meera's questions. I know she's really enjoying your book. My question is this: how would you recommend that a group get started with doing tests when their existing code base has very few or none at all? It always seems like such a daunting task. Thanks!
www.dzone.com - fresh links for developers
bestuff.com - the best stuff in the world
2 . At 9:56 AM on Oct 3, 2007, Lasse Koskela wrote:
  Click to reply to this thread Reply

Re: Excellent interview and a question for Lasse

> My question is this: how would you recommend that a
> group get started with doing tests when their existing
> code base has very few or none at all? It always
> seems like such a daunting task.

In small steps. There's little point in stopping all development so you can add those missing tests. Instead, I'd recommend agreeing on a practice that will improve the situation over time, such as, always leaving code in a better shape than you found it and writing the missing tests for classes you touch during development. That way, you'll be slowly improving the situation and improving the situation in those places you work with the most.
3 . At 10:07 AM on Oct 3, 2007, Meera Subbarao wrote:
  Click to reply to this thread Reply

writing tests as and when you find a bug

Hi Lasse, Matt,
How about adding a test as and when you find a bug? Even before fixing the bug, writing the test first should be made a priority.
Meera Subbarao
4 . At 2:32 PM on Oct 3, 2007, Tom Pridham wrote:
  Click to reply to this thread Reply

Re: Manning releases a must have book: Test Driven

Great book, really needed, well written, and greatly appreciated!

Regards,
Tom
Regards,
Tom Pridham
Technologist & Founder
Coastal Software Solutions Inc.
office: 813.600.5053
Pridham@Mindspring.com
5 . At 10:26 AM on Oct 4, 2007, Lasse Koskela wrote:
  Click to reply to this thread Reply

Re: writing tests as and when you find a bug

Whenever someone reports a defect, it's a good idea to figure out which test was missing that let the bug slip through. Sometimes it's a unit test you should've written. Sometimes it's an integration test you should've written. Sometimes it's an issue with your architecture that makes you more vulnerable to that kind of a defect than you'd like. In any case, writing a test to prove that the defect 1) exists and 2) was fixed is definitely a good practice.
6 . At 3:47 PM on Oct 4, 2007, Serge Bureau DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

I am not a big fan of TDD

This looks nice in theory and is used in many part of the company where I work.

Of course there are different tests, micro tests, functional tests,...

The ons I have problem with are micro tests, they are mainly testing nothing but the interface.
You have to create so many mock object that you are not in fact truly testing the real objects.
Plus the bugs are mostly interactions between objects, timing, database, UI. Al those are mainly for functional tests. So for me the only valuable tests are functional tests, the rest is a lot of wasted time.

Plus the argument that writing tests makes you understand your design brings you back to the waterfall model of designs. TDD might be politically correct, but for efficiency I am not so sure.
7 . At 7:20 PM on Oct 4, 2007, Meera Subbarao wrote:
  Click to reply to this thread Reply

Re: Correct link for the web site

The link in the article to Manning's web site should be:
http://www.manning.com/koskela/
Meera Subbarao
8 . At 7:22 PM on Oct 4, 2007, Meera Subbarao wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

Serge,
you mean writing unit tests and running them during nightly builds is not efficient?
Meera Subbarao
9 . At 2:00 AM on Oct 5, 2007, Lasse Koskela wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

Hi Serge,

I appreciate your opinion although it differs from mine (I don't see unit tests being wasted time).

I have to ask, though, when it comes to interaction-related defects, isn't that exactly what mock objects (and interaction-based tests) help you test for--verifying that objects interact with their buddies as expected?

I'm also curious about your comment related to understanding design and the "waterfall model of designs." I don't understand what you mean by that--could you elaborate a bit?

Thanks.
10 . At 1:26 PM on Oct 5, 2007, Serge Bureau DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

> Serge,
> you mean writing unit tests and running them during
> nightly builds is not efficient?

I am not sure what is the "unit test" stand for the same thing for everybody.
To me Unit tests are mainly microtest, test only related to a unique class.

Following that definition, there is maybe only 10% of classes really worthed writing some tests, because most classes need database access, security, network, UI, ...

So most classes need functional testing, and unit tests are not appropriate for functional testing.
To me functional testing is primordial, Unit tests are of much less value.

If TDD means the use of functional testing, then it is fine but the normal definition seems to only take care of Unit tests, if that is the case, it is overrated.

Todays bugs are mainly relation between threads (timings, locking), also all UI bugs. All those bugs are just about ignored by MicroTest, that is fine because it is the job of functional test.

TDD is for Microtest, modern tools eliminate many of those easy bug automatically any way. Am I wrong in my definitions ?
11 . At 1:40 PM on Oct 5, 2007, Serge Bureau DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

> Hi Serge,
>
> I appreciate your opinion although it differs from
> mine (I don't see unit tests being wasted time).

Hi Lasse,

It is exaggerated to say that it is a waste of time, my bad.
But I find many companies put too much emphasis on it, tome it is worthed to maybe only 10 to 15% of the code (still an important amount).

I am working on a large project and a very large part is complex relations with databases, thousands of graphical interfaces, network load, security, serialization, exchanges of objects, ...

> I have to ask, though, when it comes to
> interaction-related defects, isn't that exactly what
> mock objects (and interaction-based tests) help you
> test for--verifying that objects interact with their
> buddies as expected?

This is a minuscule part of the issue, how does it react to a large load, how about performance and timing issues, and the incredible amount of UI issues.

Mind you we have a very elegant solution for this type of testing (functional), we have an XML API that allows to run the system through real situation of our choosing.
But it is not Unit tests, and to me those are the ones where we must put the bulk. But Unit tests have their places. I just think their is too much emphasis on them.
This not a critic of your book or of Unit test, it is more kind of the mood of the market that bugs me a bit (no pun intended ;-) )

> I'm also curious about your comment related to
> understanding design and the "waterfall model of
> designs." I don't understand what you mean by
> that--could you elaborate a bit?
>
> Thanks.

By that I mean,

we are now very "agile", so we are suppose to have a minimum design and go from there, so we knd of procedd from prototype to more refined prototype.

But the TDD approach (correct me if I am wrong) seems to say write test first, so in fact have to know your design in advance to do that, so we are back to design everything first, thus waterfall
12 . At 4:21 PM on Oct 5, 2007, Lasse Koskela wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

Hi Serge,


> I am not sure what is the "unit test" stand for the
> same thing for everybody.
> To me Unit tests are mainly microtest, test only
> related to a unique class.

That's where our definitions differ. To me, a unit test isn't necessarily related to a single class (although that's often the case).


> If TDD means the use of functional testing, then it
> is fine but the normal definition seems to only take
> care of Unit tests, if that is the case, it is
> overrated.

Well, there's the concept of "acceptance test-driven development" (also known as "customer test-driven development" or "story test-driven development"), which is a bit like TDD with functional tests. Guess what - I describe the technique in the book :)


> Todays bugs are mainly relation between threads
> (timings, locking), also all UI bugs. All those bugs
> are just about ignored by MicroTest, that is fine
> because it is the job of functional test.

User interfaces definitely need functional tests and manual testing. The user interface components themselves, however, are something I'd probably write unit tests for. I've got a whole chapter in the book about test-driving Swing code.

Now, concurrent systems are tricky bastards, aren't they? And the concurrency is especially difficult to test for, even with (or should I say especially with ) functional tests.

I often say that the best way to test for concurrent behavior is to get rid of it. What I try to do when working with concurrent systems is to isolate the control over the concurrency into as few places as possible, write automated tests for that control logic, and test the rest of the system as usual (because it's effectively sequential). I talk about this in the book, too.

Eventually, though, getting concurrency right boils down to having an extremely simple architecture and having as many smart people look at it. Why? Because we simply don't have the means to control things like CPU scheduling to thoroughly exhaust all the possible executions for our concurrent system so there's always something we just have to trust that it works.


> modern tools eliminate many of
> those easy bug automatically any way.

Which tools are you using and what kind of bugs they eliminate automatically? Please do tell me if you've found a tool that can detect where I've implemented a piece of logic wrong... On a more serious note, the kind of bugs that tools like FindBugs can detect aren't exactly the kind of mistakes I'm looking to prevent with unit tests.


> Am I wrong in my definitions ?

No, you're not wrong in your definitions. Your "micro test" is simply different from my "unit test".


Lasse
13 . At 4:26 PM on Oct 5, 2007, Lasse Koskela wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

> we are now very "agile", so we are suppose to have a
> minimum design and go from there, so we knd of
> procedd from prototype to more refined prototype.
>
> But the TDD approach (correct me if I am wrong) seems
> to say write test first, so in fact have to know your
> design in advance to do that, so we are back to
> design everything first, thus waterfall

In TDD you let design emerge through programming by intention , which means you start writing a test, having an idea of behavior you want the object(s) under test to exhibit, and you write that test from the object(s) client's point of view. The test effectively defines the tested objects' interface (but not implementation) and you typically figure out the exact method signatures etc. on the spot.

Yes, you do need to have some kind of idea what you want but that goes for anything--including test-last and don't-test approaches as well as TDD. To draw a shaky analogy, your fingers aren't moving before your brain says "go" and that's not going to change.

You could say that the first implicit step before "test", "code" and "refactor" is "think". That is, you spend two seconds after finishing the previous TDD cycle to decide what you want to add to or change in the code under test--and then you start writing the test. The key thing to note here is that this isn't the same as designing everything up front.

By the way, I promoted the book at JavaRanch last week, answering questions about the book and about TDD in the Testing forum and I have to say I don't remember having as interesting a discussion as this one. Thanks :)
14 . At 10:27 PM on Oct 6, 2007, Serge Bureau DeveloperZone Top 100 wrote:
  Click to reply to this thread Reply

Re: I am not a big fan of TDD

Hello again Lasse,

so maybe we are not so diverging ;-)

The definition of TDD and Unit tests is kind of fuzzy so it is sometimes difficult to conclude.

But being a book addict I will for sure get your book.
You can always learn new things even disagreement is sometimes good, your book is not out yet, so my comment where general and not meant as an attack.

I better agree with your definition that exert many classes.

I hope you will visit Javalobby after your book is out.

Good luck.

thread.rss_message