SlideServe
Menu
Préférences
© SlideServe · v2026

Unit Testing Essentials: JUnit Framework Guide

fayola avatar
21 diapositives · 353 Views · Oct 24, 2012

The JUnit testing framework that automates unit testing and advocates the "Test a Little, Code a Little" philosophy. Discover why unit testing is crucial, its framework structure, and examples of extensions. Learn how to organize test cases, benefits of automation, and popular JUnit extensions. Enhance your development process with effective unit testing practices.

Unit Testing Essentials: JUnit Framework Guide - slide 1
01 / 21Unit Testing Essentials: JUnit Framework Guide
1 / 17

Télécharger la présentation

Unit Testing Essentials: JUnit Framework Guide
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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