-
Test Driven J2EE development (2 messages)
- Posted by: unmesh joshi
- Posted on: June 12 2005 21:42 EDT
I have been reading about TDD recently. Just curious to know if anybody has used Test Driven Development approach in their J2EE projects. What is your experience? My first impression about TDD is that its a great approach and will lead to a better design.Threaded Messages (2)
- It is by Colin Yates on June 13 2005 07:29 EDT
- About TDD, IoC, Mock, etc. by Pavel Sumarokov on December 27 2008 10:49 EST
-
It is[ Go to top ]
- Posted by: Colin Yates
- Posted on: June 13 2005 07:29 EDT
- in response to unmesh joshi
TDD *can* (not necessarily does) lead to a very clean design full of small objects doing one thing and one thing well.
Coupled with an IoC (www.springframework.org) it can be a killer :)
Also check out mock objects (jmock.org is the one I use).
You might also want to look into a continuous integration server as well (again, cactus is the one I use).
You *do* need to be careful about what you are testing. It is all too easy to test a whole graph of objects. Ideally you want to test a single class and use mock objects for it's collaborators.
J2EE does pose a horrendous problem because of it's use of container managed services. How do you unit test a sessionBean? Quite simply you cannot test it in isolation, you must test it in an application context. There are mock container implementations around (checkout junit.org).
One strategy I use is to move all my logic into Commands or helper classes which can be unit tested very easily. -
About TDD, IoC, Mock, etc.[ Go to top ]
- Posted by: Pavel Sumarokov
- Posted on: December 27 2008 10:49 EST
- in response to Colin Yates
Hi Unmesh, I've successfully used TDD in Enterprise Java applications. If you are interested in learning TDD, you can read this quick start article describing TDD with samples in Java, JUnit and JMock. Colin, I agree with you in general. TDD can be a blessing or a curse depending on your skills :) TDD and unit testing at all coupled with an IoC is my favorite style of coding in Java. It makes a code be stable, easy to test and maintain. It works because everything can be mocked so tests become really modular. I suggest to take a look at Spring for that purpose. With regard to continuous integration I would say that FIT testing or Concordion are useful frameworks in general. Truly speaking, I prefer to have thin controllers in Web applications rather than cover it with Cactus based tests. In my opinion, there is only one problem preventing developers to use TDD. It is inertness of our mind.