80 likes | 219 Views
Test-Driven Development. CSE301 University of Sunderland Dr. Giles Oatley. Sources. Fowler, 2000, Refactoring: Improving the Design of Existing Code, Addison-Wesley. http://www.amazon.com/exec/obidos/tg/detail/-/0321109295/103-4060125-0311065
E N D
Test-Driven Development CSE301 University of Sunderland Dr. Giles Oatley
Sources • Fowler, 2000, Refactoring: Improving the Design of Existing Code, Addison-Wesley. • http://www.amazon.com/exec/obidos/tg/detail/-/0321109295/103-4060125-0311065 • http://www.amazon.com/exec/obidos/ASIN/0130648841/103-4060125-0311065 • http://www.refactoring.com/catalog/ • http://www.win.ua.ac.be/~lore/refactoringProject/index.php • Extensive discussions on the comp.object newsgroup.
Topics • Test-Driven Development • JUnit • Refactoring • Principles • Bad Smells in Code • A Catalog of Refactorings
Test-Driven Development • The test-driven development is the method of software development where tests specify interfaces of implementation and all code must have passed the tests. (Wikipedia)
Test-Driven Development Roughly: 1. Write a test for a bit of functionality. 2. Show that it fails. 3. Write the code to make the test pass. Additionally. 1. Do not write production code until there is a failing test. 2. Write the simplest possible production code to get the test to pass. 3. Do not write more tests when we have a failing test. 4. Do not add to a failing test.
Further Comments • If you watched someone doing TDD you would see them oscillating between test code and production code once every minute or so. • During each oscillation the programmer would add a few lines to his test code, thus making it fail (or not compile) and then add just a few lines to his production code in order to make the test pass (or compile). • Each oscillation is so simple that it's not worth taking. • Each oscillation is so simple that the risk of error is close to zero. • If you walk into a room of people working this way, and chose anyone at random, a minute ago all his code would have been working.
Working with JUnit IMPORTANT TUTORIAL WORK • Eclipse version (at least) 3.0. • Download and install the examples. • Create a JUnit project. Read the test examples provided for ideas. • Open the properties for your project. Go to Project References and select the JUnit project. • Create an AllTests class for your project to run your test suite. • Create appropriate unit test classes and insert them in your test suite.
Eclipse and TDD • Work through the Eclipse-JUnit tutorial at: http://www.onjava.com/pub/a/onjava/2004/02/04/juie.html