| By John Evans, Richard Cariens | Article Rating: |
|
| July 31, 2006 05:15 AM EDT | Reads: |
28,072 |
Lucky for us, the test passes!
After congratulating ourselves on our success, we realize that the <link> attributes might appear in any order and with embedded new lines. We decide to write a second test to handle this new scenario. This test case switches the "type" and "href" attribute ordering and adds a new line between them.
Sure enough, we find that our FeedAutoDiscoverer doesn't handle this scenario; the new test fails.
We open up the FeedAutoDiscoverer and tweak the regular expression so that it'll hopefully handle the new scenario:
- We add an OR operator to the original expression and switch the order of the "type" and "href" attributes in the new half;
- We add the DOTALL flag to the expression, which allows the '.' character to match new lines.
Running the test again results in failure, but it looks like the regular expression may have worked since it's the contents of the list that are wrong. Reviewing our changes shows us that we forgot to update our capture group handling. We have two capture groups in the regular expression and have to add the proper group contents depending on which half of the regular expression worked, so we change our logic.
We find that the test now passes and we're ready to move on to adding more tests for auto-discovering Atom link references, etc.
There's a lot more to do, but we're well on our way to delivering the site "Feed Finder" service. If we wanted to, we could stop here with auto-detection and start building out the downloader component and the servlet, or we could extract an interface from the FeedAutoDiscoverer and start work on fitting it into an IoC container like Spring. Whatever we decide to do, we now have two tests that we can use to sanity-check changes we make from this point forward that might impact feed auto-discovery. If these tests continue to pass as we change the system (and we should run our tests often), we'll become more confident and comfortable with handling change.
(As an aside, at this point in real life, we discovered that there was actually a spec for ATOM-based feed auto-discovery at http://philringnalda.com/rfc/draft-ietf-atompub-autodiscovery-01.html. So, we took each of the examples in the RFC and coded them up as unit tests, and made sure that our FeedAutoDiscoverer successfully discovered them.)
Conclusion
Test-driven development helped us in many ways on this project:
- It forced us to translate our ambiguous requirements into verifiable test criteria;
- The test criteria helped us focus on doing just what was needed to pass the test, and thus hopefully satisfying the requirements;
- We avoided the heavy front-loading of design documentation and focused on getting some working code.
References
- http://extremeprogramming.org/rules/testfirst.html
- http://extremeprogramming.org/stories/testfirst.html
- http://en.wikipedia.org/wiki/Test_driven_development
- www.testdriven.com/
- www.aaronsw.com/2002/feedfinder/
- www.syndic8.com/web_services/
- http://java-source.net/open-source/html-parsers
- http://mercury.ccil.org/~cowan/XML/tagsoup/
Published July 31, 2006 Reads 28,072
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By John Evans
John Evans is the founder and president of JPEvans, Inc. (www.jpevans.com), a small independent computer consulting company based in Northern Virginia just outside of Washington D.C. John has over 10 years of professional experience in software development. He has successfully developed and deployed large-scale software systems for several large multi-national corporations.
More Stories By Richard Cariens
Richard Cariens is an independent software consultant in the Washington D.C. area (www.jpevans.com). He has over 10 years of experience testing, developing, designing, and architecting Internet technology and financial systems. Rich holds an MS in computer science from George Mason University in Fairfax, Virginia.
![]() |
The Cherbin 08/22/06 06:35:33 PM EDT | |||
The best way to write right java is either |
||||
![]() |
JDJ News Desk 07/30/06 11:36:06 AM EDT | |||
Testing Java code is increasingly a task taken on by developers rather than separate teams to which the programs are handed. Many Java developers are now familiar with JUnit and know the different between unit tests and integration tests. This has been driven largely by the focus on test-driven development (TDD) in extreme programming (XP) and other agile software development methodologies. While the industry-at-large has recognized the value of unit tests and has a new outlook on testing in general, for the most part, actual TDD (meaning, the tests are written first) is not usually practiced outside of hardcore agile shops. |
||||
![]() |
JDJ News Desk 07/30/06 08:56:13 AM EDT | |||
Testing Java code is increasingly a task taken on by developers rather than separate teams to which the programs are handed. Many Java developers are now familiar with JUnit and know the different between unit tests and integration tests. This has been driven largely by the focus on test-driven development (TDD) in extreme programming (XP) and other agile software development methodologies. While the industry-at-large has recognized the value of unit tests and has a new outlook on testing in general, for the most part, actual TDD (meaning, the tests are written first) is not usually practiced outside of hardcore agile shops. |
||||
![]() |
Jon Log 07/26/06 05:22:53 AM EDT | |||
Though the development in question is a trivial one, your conclusions encapsulate perfectly why TDD is a poor substitute for a proper development model: Conclusion 1: "It forced us to translate our ambiguous requirements into verifiable test criteria" But on whose terms ? The "us" in your statement implies that you mean the developer. This is WRONG. An ambiguity must be flattened out by the specifier and agreed on by the developer. This is the contract you have with whoever you are providing a solution for. A developer is just as likely to interpret an ambiguity incorrectly as correctly. Conclusion 2: "The test criteria helped us focus on doing just what was needed to pass the test, and thus hopefully satisfying the requirements" Well, "hopefully" is not good enough. The objective of the developer MUST be to make their code do what it should in relation to the requirement. By encouraging a coder to produce something that meets only the requirements of a test that they themselves have defined is obviously a corrupt concept. Focussing on the test rather than the true objective of the requirement breaks a valuable chain of responsibility that should exist at every stage of the process. Conclusion 3: "We avoided the heavy front-loading of design documentation and focused on getting some working code." This is the icing on the cake. Spending time thinking about and documenting a design delivers too many obvious benefits to mention. However, in relation to the anti-patterns that I believe are a core part of your conclusions, designing a solution before implementing it would force any ambiguities to be resolved at the correct time and in the correct manner (against a coherent definition that is intelligible to the business and development communities). In addition, assuming that a solution involves more that one method (which of course it generally does) it would promote the production of a more appropriate test path with the requirements taking precedence over the tests themselves. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?






































