Description
This Java Testing with JUnit 5 training class introduces experienced Java developers to the fundamentals and best practices in unit testing. It uses the JUnit 5 and Mockito libraries, both of which are ubiquitous in the Java community. It is intended for both developers who are new to testing, as well as those who are already familiar with it, but want more experience with testing using JUnit 5. Note that JUnit 5 is substantively different than JUnit 4. Although the core testing principles are the same, there are substantial implementation differences, important new features, and a brand new extension model. Developers with JUnit 3 and 4 experience will be well-served by the course. All labs are done with the Eclipse IDE, and the lab instructions include detailed directions for setting up and using it. The standard application server used is TomEE, but it is available for other major app servers, including WildFly/JBoss AS and IBM WebSphere AS.
Objectives
Upon successful completion of this course, the student will be able to:
- Understand new JUnit 5 library structure, role of each component, and how they interact
- Configure IDE projects to run tests natively, and via Maven Surefire
- Write cohesive and effective tests, and design classes for testability
- Understand the full test lifecycle, and employ it to configure test fixtures
- Run tests using all available mechanisms: IDE, Maven, JUnit Console Launcher, Launcher API
- Use test discovery and filtering to define and run test plans, including conditional test execution
- Employ naming conventions at every level - test name, classname, display name
- Organize tests with assertion groups and nested tests
- Use test interfaces to apply good OO principles to testing
- Understand the new JUnit extension model, and how to write and use them
- Understand JUnit 4 compatibility and migration
- Use mock objects with Mockito to support isolated testing
- Explore Mockito's facilities for dependency injection of mocks
- Use argument matchers for more generalized testing with mocks
- Implement partial mocking with spies
- Understand the issues in testing enterprise components
- Understand the two basic approaches: standalone testing with mocks, and in-container testing
- Test database access components, using both fakes and an embedded database
- Understand the additional issues involved in testing the service and web layers
- Exercise best practices throughout the testing effort
Prerequisites
Good working knowledge of Java and OO, including the use of interfaces, abstract classes, collections, factories, and generics. Experience with Java 8 lambda expressions is helpful, but not strictly required.