IMPORTANT: Visit our other site for training details and registration. We are moving the training related content to that site.

Test Driven Development With JUnit And Its Extensions

Delivered to any part of the world over the Internet!

Participate and pay if you like! Click here to request participation


Test driven development (TDD) which is also known as test first programming or test infected programming refers to the practice of software developers where they write code test cases before the actual application code is written. This practice enhances the code and design quality of the software, reduces bugs and improves the overall software development efficiency.

JUnit is a Java library that facilitates TDD in Java. It is the de facto standard. It has many extensions and has also been ported to many different programming languages. This training program focuses on TDD with JUnit and some of the widely used extensions.

Training Objectives:

At the end of the training, participants will be able to

  1. Describe the benefits of test driven development and practice the same.
  2. Design, organize and develop good unit tests with JUnit.
  3. Use JUnit 3 and 4 syntax to code JUnit test cases.
  4. Use JUnit with different development environments (Eclipse, Ant, Maven).
  5. Use DbUnit to test database related code.
  6. Describe what mock object testing is and use EasyMock to do the same.
  7. Use HttpUnit and jWebUnit for web application functionality testing.
  8. Follow best practices in using JUnit and the extensions to improve the development efficiency and software quality.

Target Groups:

  1. Java developers


  1. You should be familiar with Java programming language. Expert knowledge is not needed.

Communication Language:



6 hours


Kamal Wickramanayake (Profile)

Training Content:

  1. Introduction to Test Driven Development
    • What is test driven development (or test infected programming)?
    • What is unit testing?
    • Comparing unit testing and debugging
    • Who should write these tests?
    • Qualities expected from a regression testing framework
  2. Introduction to JUnit
    • Possible code testing mechanisms
    • JUnit as a regression testing framework for Java
    • How to represent a test in JUnit?
    • TestCase class and different assertions
    • Running a test
  3. Test Organization
    • Using different source directories for tests and application code
    • Implementing multiple tests within a TestCase
    • Test fixture
    • Test code skeleton auto generation
    • TestSuites
  4. Special Test Scenarios
    • Testing for exceptions
    • Difference between errors and failures
    • Testing code that spawns new threads
    • Issues with singletons
  5. Development Environments, Test Runners and Reports
    • Using JUnit with Eclipse, Ant and Maven
    • Generating test reports (XML, HTML)
    • Running JUnit 4.x tests with a 3.x test runner
  6. JUnit Best Practices
    • Garbage collection of tests and working with large code bases
    • Bug fixing assisted by unit tests
    • Code refactoring assisted by unit tests
    • Improving class modularity and testability
    • What to test and what not to test?
  7. Introduction to DbUnit
    • Difficulties encountered in unit testing database related classes
    • How does DbUnit solve them?
  8. A DbUnit Example
    • Creating a dataset file
    • Creating the test class
    • Database data verification
    • Running the test
  9. DbUnit Best Practices
    • One database instance per developer.
    • One test at a time.
  10. Introduction to Mock Object Testing
    • Testing classes that depend on other classes
    • The role of mock objects
    • A primitive approach in creating mock objects (Write them for your self)
  11. Mock Object Testing with EasyMock
    • Installation
    • Creating a mock object from an interface dynamically
    • Specifying the expectations, exercising the test methods, verification
    • Specifying return values
    • Working with exceptions
    • Argument matching
    • Limitations of EasyMock
    • Mock objects for concrete classes
  12. JUnit Extension: HttpUnit for Web Application Testing
    • Functionality testing with HttpUnit (as opposed to unit testing)
    • Writing a test case with HttpUnit
    • Executing the tests
    • Overview of HttpUnit API
    • How to tackle JavaScript errors in a web page?
  13. JUnit Extension: jWebUnit for Web Application Testing
    • Example jWebUnit test
    • HttpUnit Vs jWebUnit
  14. End Notes
    • Overview of some other useful JUnit extensions
    • What is in-container testing?
    • Costs Vs benefits of writing unit tests