This article, the first in a four part series on test-driven development (TDD), introduces TDD and provides references to tools that are useful for TDD. Upcoming topics covered in this series include unit testing of EJB components and POJO classes, black box and in-container testing of servlets and JSPs, and in-container testing of Struts web applications.
Read Test-Driven Development Series Part 1 - Overview
-
Test-Driven Development Series Part I: Concepts and Tools (16 messages)
- Posted by: Nitin Bharti
- Posted on: December 30 2003 11:42 EST
Threaded Messages (16)
- WebTest also worth a look by Eric E on December 30 2003 16:36 EST
- TDD is not about testing ... by Jon Eaves on December 30 2003 21:19 EST
- TDD is not about testing ... by Damian Guy on December 31 2003 12:00 EST
- In container testing of struts applications? by xxx yyy on December 31 2003 11:08 EST
- Agree as well by Sheng Sheen on December 31 2003 12:13 EST
- BPEL for building test framework by Pranab Ghosh on December 31 2003 13:23 EST
- JMeter is good as well by marc schipperheyn on January 01 2004 17:11 EST
- Article is not about TDD exactly! by Prakash Anthony on January 02 2004 10:36 EST
- The selection of tools by COBBIE BEHREND on January 02 2004 12:19 EST
- TDD and EJBs by Stephan Westen on January 05 2004 15:50 EST
- TDD and EJBs by COBBIE BEHREND on January 05 2004 17:33 EST
- TDD and EJBs by Perryn Fowler on January 06 2004 06:48 EST
- TDD and EJBs by Rod Johnson on January 07 2004 03:34 EST
- TDD and EJBs by Ilya Kosolapov on January 06 2004 14:58 EST
- TDD and EJBs by Ilya Kosolapov on January 07 2004 09:30 EST
- TDD is a New Concept by Barney Rubble on August 19 2005 17:42 EDT
-
WebTest also worth a look[ Go to top ]
- Posted by: Eric E
- Posted on: December 30 2003 16:36 EST
- in response to Nitin Bharti
jWebUnit is mentioned as a "macro library for HttpUnit". Another similar tool that also sits on top of HttpUnit is WebTest (http://webtest.canoo.com).
The difference is that in WebTest the test steps are defined in XML and are executed in custom ANT targets. I found it quite pleasant to use. -
TDD is not about testing ...[ Go to top ]
- Posted by: Jon Eaves
- Posted on: December 30 2003 21:19 EST
- in response to Nitin Bharti
... it's about design. The article just talks about how good testing is (which it is) and the benefits of having lots of tests that can be automated (which are great).
The real benefit of TDD is the design process. With TDD and refactoring, a design can emerge in a positive direction as the test cases are first class users of the code. This requires the code that is under development to be well constructed and modular to allow for this to happen, and not the "standard" unit testing of "set up the container, run some end-to-end tests and pat yourself on the back".
For some really good quality books and articles on TDD have a look at these:
Dan North's article (and also covered by TSS)
http://www.sys-con.com/story/?storyid=37795&DE=1
Ken Beck's book _Test Driven Development: By Example_
and my favourite
Robert C. "UncleBob" Martin's _Agile Software Development, Principles, Patterns, and Practices_.
Please don't think about TDD as testing, because if you do, you're missing the point. -
TDD is not about testing ...[ Go to top ]
- Posted by: Damian Guy
- Posted on: December 31 2003 12:00 EST
- in response to Jon Eaves
Agreed! This article completely misses the point of TDD. It should be re-named to "Automated Testing" or similar.
TDD is about design, the tests are just a side effect.
Read Dan North's article! -
In container testing of struts applications?[ Go to top ]
- Posted by: xxx yyy
- Posted on: December 31 2003 11:08 EST
- in response to Nitin Bharti
StrutsTestCase also allows for testing with mock objects and it works great. No need to start/stop servers, no nothing, just run these tests along with all your other junit tests without hassle or loss of time. With mock objects and refactoring, what are the rare cases where in-container testing of server-side code is still needed? -
Agree as well[ Go to top ]
- Posted by: Sheng Sheen
- Posted on: December 31 2003 12:13 EST
- in response to Nitin Bharti
This article should really be renamed to Unit Testing Tools, or Automated Testing, or even Regression Testing.
Very poor introduction to TDD. Doesn't explain the evolution of TDD, but just goes right into the tools. -
BPEL for building test framework[ Go to top ]
- Posted by: Pranab Ghosh
- Posted on: December 31 2003 13:23 EST
- in response to Nitin Bharti
I have used BPEL ( http://www-106.ibm.com/developerworks/webservices/library/ws-bpel/ ) to build a test framework that I am using for my current project. Although BPEL is meant for business process orchestration, it's working out nicely as a test framework. Variable and Assign semantics in BPEL allowed me to do functional testing of complex statefull use cases. The only downside was that I had to expose as web services whatever server side functions I wanted to test .
Pranab -
JMeter is good as well[ Go to top ]
- Posted by: marc schipperheyn
- Posted on: January 01 2004 17:11 EST
- in response to Nitin Bharti
It allows you to programmatically recreate the way the user walks through an application. It is aimed at web applications. Disadvantage is that you do have to specify form fields and values for testing of posting of forms. But you can let the script do things like log in to a site and work with conditions and branches. It also allows for load testing.
http://jakarta.apache.org/jmeter/
Marc -
Article is not about TDD exactly![ Go to top ]
- Posted by: Prakash Anthony
- Posted on: January 02 2004 10:36 EST
- in response to Nitin Bharti
The article starts with TDD, only then to deviate to talk about automated testing. TDD is all about "Test Perspective" right from the design phase. As some one has said earlier, may be worth removing TDD from the title. -
The selection of tools[ Go to top ]
- Posted by: COBBIE BEHREND
- Posted on: January 02 2004 12:19 EST
- in response to Nitin Bharti
Seems strange that StrutsTestCase is included in the tools section. While it is a great tool for testing Struts mappings (and in my opinion that's all it should be testing) is it not a bit too specific? You would think that Cactus, MockObjects, and or EasyMock (as well as the extention that allows mocking of classes - for example see http://blogs.codehaus.org/people/vmassol/archives/000250_mocking_classes_with_easymock.html) would be more appropriate in an article that aims to cover TDD in general. Not including mocking in the overview and at least one tool would place a huge obsticle in front of someone who was trying to unit test code in isolation. In the case of Struts your action tests would become acceptance tests, which does not need to be the case if they are tested as independent units, and adds unnecessary complexity to your test. -
TDD and EJBs[ Go to top ]
- Posted by: Stephan Westen
- Posted on: January 05 2004 15:50 EST
- in response to Nitin Bharti
I agree that test-driven development is more than suggested in this article. You start with a test that fails, make it work, etc. This makes me curious how other development teams combine this with EJB development. Using Cactus takes a lot of time (compiling and deploying to app server can take several minutes). TDD requires that you can update your code and run your tests very quickly.
Using mock objects could work, but can also be difficult when using transaction and other container related features (e.g. queues). What we are looking for is hot-deployment of a single EJB instead of a complete application. Ideas?
Stephan -
TDD and EJBs[ Go to top ]
- Posted by: COBBIE BEHREND
- Posted on: January 05 2004 17:33 EST
- in response to Stephan Westen
Using mock objects could work, but can also be difficult when using transaction and other container related features (e.g. queues). What we are looking for is hot-deployment of a single EJB instead of a complete application. Ideas?
What app server are you using?
This has worked for me on JBoss and OC4J. In a directory named test have a seperate build.xml and configuration files for building a test EAR file. The build.xml grabs IDE compiled code (saving time) and 1) puts it all together 2) copies the file to the server. Total time running the build.xml should not be more than a several seconds, depending on how many jars are needed to support the EJB, and provided that the build.xml does not need to compile and can just grab classes. If things still take too long then something can always be decoupled and mocked (chosen in order of greatest complexity first).
Mostly though, I stay away from EJBs because I don't have distributed transactions. -
TDD and EJBs[ Go to top ]
- Posted by: Perryn Fowler
- Posted on: January 06 2004 06:48 EST
- in response to Stephan Westen
Ahah!
This is exactly what Jon and others are talking about - TDD is about design. If it is hard or time consuming for you to test in-container then design your code to minimise the amount of in-container testing you have to do..
write your EJBs to delegate business functionality to POJOs ( plain old java objects) so that the EJB itself is just a shell that provides an execution context. Then exhaustively test the POJOs with fast out-of-container tests.
Now all you need is one in-container integration test to make sure eveything hangs together.
But what if the POJOs need to use services like queues etc? Then mock them
for your POJO tests. But those are complex interfaces and hard to mock? then dont mock them. Have the POJO itself delegate message sending to a MessageSender class that know how to talk JMS and has a much simpler interface itself. Then mock *this* class when testing your POJO to check the POJO uses MessageSender correctly. Now all you need is a quick test of the real MessageSender to check it really knows how to talk JMS.
oh and look, almost by accident, if we ever want to change the app to talk something other than JMS we have a design that facilitates an easy change by swapping in a new version of MessageSender..... -
TDD and EJBs[ Go to top ]
- Posted by: Rod Johnson
- Posted on: January 07 2004 03:34 EST
- in response to Perryn Fowler
Yes, out-of-container testing is essential, where unit testing is concerned. You can't usually get equal code coverage testing in the container--although of course you need to perform integration tests as well.
This is exactly what Jon and others are talking about - TDD is about design. If it is hard or time consuming for you to test in-container then design your code to minimise the amount of in-container testing you have to do..
Spring is designed to facilitate this. For example, you never need to use JNDI directly, even if you use EJB: you just get to work with the business methods interfaces of your EJBs directly: the container provides the reference with no lookup required. Practising TDD is easy.
As Perryn points out, if you have an abstraction interface that doesn't depend on the container, mocking is easy and reuse is easy in different contexts. -
TDD and EJBs[ Go to top ]
- Posted by: Ilya Kosolapov
- Posted on: January 06 2004 14:58 EST
- in response to Stephan Westen
Using mock objects could work, but can also be difficult when using transaction and other container related features (e.g. queues). What we are looking for is hot-deployment of a single EJB instead of a complete application. Ideas?
Check out www.mockejb.com ... -
TDD and EJBs[ Go to top ]
- Posted by: Ilya Kosolapov
- Posted on: January 07 2004 09:30 EST
- in response to Ilya Kosolapov
That should have been www.mockejb.org ... Sorry for confusion,
Ilya. -
TDD is a New Concept[ Go to top ]
- Posted by: Barney Rubble
- Posted on: August 19 2005 17:42 EDT
- in response to Nitin Bharti
The article's introduction brings to the attention of the reader a concept called test-driven development and calls it "new". How was the rest of the article? Don't know. I would not waste my time reading an article by anybody that ignorant. Go back and read Mythical Man-Month and 10,000 other books that covered the topic in the last century.