Extreme Programming: Automated Testing and Refactoring CSCI 4300
WAR project development setup addressBook.war contains the entire deploy directory Drop the war file into the JBOSS deploy directory!
Adding Automated Testing
Integrating testing into build.xml <target name=“test” depends=“compile”> <junit printsummary=“true”> <test name=“BeanTest.allTests” /> <classpath path=“./test” /> </junit> </target> <target name=“deploy” depends=“test”>
Refactoring with XP Problem: in a large project, touching a piece of code carries a 50% chance of breaking it Subtle errors might go unnoticed for some time Coward Solution: If it ain’t broke, don’t fix it XP Solution: Refactor at will, but use automated testing.
AddressBook Example Version 1: uses a session bean, which forgets addresses between sessions Version 2: uses an EJB that holds open a persistent database connection Version 3: uses an EJB with container-managed persistence --All these versions should use the same interface and automated unit tests!
XP Incremental development Start with a “user story” describing usage Build a simple working version, then increment Automated testing protects you from entering subtle bugs
Designing the AddressBean test Store a name and email, then fetch the email Fetch a nonexistent entry Test number of entries
The last word “Testing is for bunglers. Properly constructed devices work properly.” --E.E. “Doc” Smith, Skylark Three (1930)