1 / 21

Test a Little, Code a Little

Test a Little, Code a Little. Colin Sharples IBM Global Services New Zealand. Overview. JUnit a Java instance of the Gamma/Beck xUnit framework architecture Automates unit testing Promotes a development philosophy of: “Test a Little, Code a Little”. Talk outline. Why do unit testing?

fayola
Download Presentation

Test a Little, Code a Little

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand

  2. Overview • JUnit • a Java instance of the Gamma/Beck xUnit framework architecture • Automates unit testing • Promotes a development philosophy of: “Test a Little, Code a Little”

  3. Talk outline • Why do unit testing? • Framework description • Development Philosophy • Extensions • Demo

  4. Why do unit testing?

  5. Ariane 5 Flight 501 Launched: 4 June 1996, 12:33:59 Exploded: 4 June 1996, 12:34:38

  6. Framework description

  7. What is a unit test? • Exercises a “unit” of production code • in isolation from rest of system • checks results are as expected • A “unit” is a coherent piece of functionality • Java class or package

  8. TestCase • Encapsulates the set of tests for one unit • public void testXxx() {} • Contains the “fixture” for multiple tests • public void setUp() {} • public void tearDown() {} • Implements the Command pattern • public void run(TestResult result) {}

  9. Assert • Methods for checking test conditions • assertTrue() • assertNull() • assertNotNull() • assertEquals() • assertSame • fail()

  10. TestSuite • Collects tests and test cases into suites • a suite for all the tests in a single test case • a suite for all the test cases in a package • a suite for all test cases in a component • a suite for all test cases in an application

  11. TestResult • Gathers results from tests • failures (anticipated, check by assertions) • errors (unanticipated, e.g. runtime exceptions) • Collates all results from a single suite • Can check if an error should stop the test run

  12. TestRunner • Provides a runtime execution environment • Runs individual tests or suites • Graphical and text based user interfaces • Swing interface • Text interface integrates with Ant • Plugin for Eclipse

  13. Extension Points • Extend TestCase or TestSuite • ExceptionTestCase • ActiveTestSuite • Provide additional testing support • TestDecorator • TestSetup • Your extension here...

  14. Development Philosophy

  15. Test a little, code a little • Core philosophy • write tests first • then write the code to make the tests work • when the tests work, you’re done :-)

  16. Unit testing saves time • Unit tests exercise the design • Unit tests give the developer confidence • Unit tests speed up integration testing

  17. Automation is the key • Tests are useless if they are not run • JUnit allows easy automation of tests • Automatic tests ease integration testing • Automatic tests ease regression testing • Automatic tests allow installation verification

  18. Test case organisation • Two options: • place test cases in a “test” sub-directory • place test cases in same package in a different source tree • Allow for separation of test code and production code

  19. JUnit Extensions

  20. Example JUnit extensions • StrutsTestCase • automated testing of Jakarta Struts applications • JXUnit • provides support for data centric testing • HttpUnit • automated web site testing

  21. Resources • www.junit.org • articles, hints & tips • downloads • www.eclipse.org • Eclipse IDE • junit plugin

More Related