Skip to content

Latest commit

 

History

History
38 lines (23 loc) · 1.93 KB

File metadata and controls

38 lines (23 loc) · 1.93 KB

Lesson 1: JUnit

Overview

Testing is done at different levels and in different ways.

  • Screen testing/system testing: Testing an application after deployment
  • Unit testing: Testing a specific method or a class

Unit testing usually involves writing tests for each method of a class. Unit tests can also be written for a group of methods or to test the whole class.

Demonstrated Concepts

JUnit Architecture

JUnit is a popular unit testing framework which automates the testing process so that tests can run continually. If there is a change in the code such that the functionality changes, automated testing will catch it.

JUnit tests compare the actual output to the expected output to check if the code is working correctly and notify the developer if it is not.

JUnit 5 changed the monolithic architecture of JUnit 4 to have separate jar files for the JUnit platform (test engine), Jupiter (JUnit 5 tests), Vintage (JUnit4 tests), and 3rd party extensions while also adding support for new testing patterns. Most IDE’s have built-in support for JUnit 5.

JUnit tests are automated meaning that the test can be kept running any number of times. The tests can be run every hour or every time there is a change in the code. The developer is notified whenever a test fails. These tests can be run under continuous integration.

JUnit dependency

To enable JUnit, we need the JUnit engine and the Jupiter API to create tests. When creating a Spring Boot project, JUnit is already included as a dependency. For other cases, the JUnit dependency can be added as follows:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <scope>test</scope>
</dependency>

<scope> specifies where we want the jars to be active. test scope means that this dependency will not be included in the final build.