Download presentation
Presentation is loading. Please wait.
Published byBarbra Cain Modified over 9 years ago
1
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.