Unit Testing using JUnit

Course Code: JUNIT

Duration: 3 days

 
 

Unit Testing using JUnit Course Overview

JUnit is the most popular and widely used Java unit testing framework.

This hands-on course, delivered using JUnit v5, comprises sessions dealing with unit testing, setup, annotations, assertions and assumptions, conditional tests, parameterised tests, stubbing and mocking, Mockito, DAO and Servlet testing, testing multi-threaded code, and TDD.

Exercises and examples are used throughout the course to give practical hands-on experience with the techniques covered.

Course Objectives

This course aims to provide the delegate with the knowledge to be able to design and code good quality, isolated unit tests with JUnit that exploit all the features of the JUnit framework.

Who will the Course Benefit?

This Unit Testing using JUnit course will benefit Java developers and testers who are new to JUnit and/or unit testing more generally.

Skills Gained

The delegate will learn and acquire skills as follows:

  • Define unit testing and describe the structure of a test
  • List some guidelines for writing good quality unit tests
  • Install JUnit
  • Code a JUnit test class
  • List and describe the primary JUnit annotations
  • Select the most appropriate assert method for the task at hand
  • Code conditional tests
  • Code parameterised tests
  • Describe the purpose of and difference between stubbing and mocking
  • Exploit Mockito to perform stubbing and mocking
  • Code tests for IO methods and DAOs
  • Describe how to deal with the testing of Servlets
  • Test multi-threaded code
  • Describe the principles of TDD

Unit Testing using JUnit Training Course

Course Introduction

  • Administration and Course Materials
  • Course Structure and Agenda
  • Delegate and Trainer Introductions

Session 1: UNIT TESTING

  • What is unit testing
  • The purpose of unit testing
  • Terminology
  • The structure of a test
  • Assertions
  • Code coverage
  • Guidelines for writing good unit tests
  • Other types of testing

Session 2: GETTING STARTED WITH JUNIT

  • What is JUnit
  • The main features of JUnit
  • JUnit in IntelliJ
  • JUnit with Maven/Gradle
  • A simple unit test
  • Alternatives to JUnit

Session 3: ANNOTATIONS

  • @Test
  • @BeforeEach
  • @AfterEach
  • @BeforeAll
  • @AfterAll
  • @TestMethodOrder
  • @TestInstance
  • @DisplayName
  • @Disabled
  • @Timeout
  • @ExtendWith

Session 4: ASSERTIONS & ASSUMPTIONS

  • assertEquals
  • assertTrue/False
  • assertNull
  • assertThrows
  • assertArrayEquals
  • assertIterableEquals
  • assertLinesMatch
  • assertSame
  • assertInstanceOf
  • assertTimeout
  • assertNot*
  • assertAll
  • fail
  • assumeTrue/False
  • assumingThat

Unit Testing using JUnit Training Course

Session 5: CONDITIONAL TESTS

  • OS conditions
  • CRE conditions
  • System property conditions
  • Environment variable conditions
  • Custom conditions

Session 6: PARAMETERISED TESTS

  • What is a parameterised test
  • The junit-jupiter-params artefact
  • @ParameterizedTest
  • Consuming arguments
  • Argument sources
  • Argument conversion
  • Argument aggregation
  • Customising display names

Session 7: STUBS, MOCKS, & PROXIES

  • Dependencies
  • Test doubles/fake objects
  • Stubs
  • Mocks
  • Proxies

Session 8: MOCKITO

  • What is Mockito
  • The mockito-core and mockito-junit-jupiter artefacts
  • The Mockito JUnit extension
  • Creating a mock/spy
  • Setting expectations (when, then)
  • Argument matchers
  • Verifying behaviour
  • Spying
  • Annotations
  • Mocking static methods

Unit Testing using JUnit Training Course

Session 9: IO, DAO, & SERVLET TESTING

  • Testing methods that use IO streams
  • Testing DAOs by rolling back transactions
  • Moving business logic out of the Servlet to simplify testing

Session 10: TESTING MULTI-THREADED CODE

  • Sharing data among threads (a review)
  • The difficulty in testing concurrent applications
  • Testing the code with one thread
  • Testing the code with many threads
  • @RepeatedTest
  • The problem with non-deterministic tests
  • 3rd-party libraries
  • Best practices

Session 11: TEST-DRIVEN DEVELOPMENT (TDD)

  • What is TDD
  • The pros and cons of TDD
  • The three rules
  • The red green refactor lifecycle
Notes:
  • Course technical content is subject to change without notice.
  • Course content is structured as sessions, this does not strictly map to course timings. Concepts, content and practicals often span sessions.

Requirements

Delegates attending this course should be familiar with basic programming concepts and have some experience coding with Java at least. Ideally delegates will be competent Java developers who have a good understanding of OO principles and are able to build simple applications that exploit APIs including Collections, IO, and JDBC. This knowledge can be obtained by attendance on the pre-requisite Java Programming 1 / Java Developer course.

Pre-Requisite Courses

Public Scheduled Events

Classroom & Live Virtual Instructor-Led Training

Duration: 3 days

Price: £1,495.00 exc. VAT 


Start Date Options Spaces  
28 Jun 2023
StayAhead Virtual Courses available 
Spaces Book Now  @ £950.00 exc. VAT 
06 Sep 2023
StayAhead Virtual Courses available 
Spaces Book Now  @ £950.00 exc. VAT 
01 Nov 2023
StayAhead Virtual Courses available 
Spaces Book Now 
 

Live Virtual Classroom

 
Join live instructor-led classroom training from the comfort of your home or office.
All the convenience and benefits of the classroom experience without the hassle and costs of travel and accommodation.
 
 



Our Customers Include

 
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
missing image
 
 



Our Course Curriculum

 
 
 
+44 (0)20 7600 6116
Enquiries@StayAhead.com
Copyright © 2023 StayAhead Training Ltd
Cookies   /   Privacy Policy