
Master JUnit five and Mockito with Spring Boot through an industry-level project, covering assertions, annotations, service-to-controller-to-repository testing, integration testing, parameterized tests, test driven development, and 100% code coverage.
Install and configure essential tools for this course: JDK 21, set its path, install IntelliJ IDEA Community, and optionally Postman to hit APIs and test endpoints.
Access the course git repository to review all pushed code and use the upcoming link for quick reference; ask questions in the Q&A if you get stuck.
Create a spring boot app via start.spring.io, set java maven project with spring boot 3.5.3, group com.testing, artifact junit, include spring web, then extract and import into IntelliJ.
Import the preexisting project into IntelliJ IDEA by moving it to the C drive and creating a testing folder. Open the project in the current window and trust it.
Set the correct JDK in IntelliJ by opening project structure, selecting the sdk under project, and choosing your installed JDK; adjust modules language level and press okay to compile.
Navigate the project structure (src/main and src/test), the resources and application properties, and learn how mvnw, pom.xml, and spring boot dependencies enable testing with a default JUnit test.
Create a new Java class called math operations in the basic package, and implement a simple sum method that accepts two integers and returns their sum.
Create an isEven method to determine if a number is even by checking divisibility by two and returning a boolean.
Create the first test class to validate math operations, organize test and main folders into a consistent com.testing.junit package, and add a basic package with a math operations test.
Create a test method in the math operations test to validate the sum method by invoking it with two numbers and storing the result as the actual value.
Explore using JUnit's assertions to verify test results by comparing expected and actual values with assertEquals, and understand pass or fail outcomes in unit tests.
Use the @Test annotation to run individual test methods in a JUnit 5 test class, execute tests via the IDE play button or Maven, and verify expected versus actual results.
Learn how to run test cases in IntelliJ Idea by executing single tests with the play button, all tests in a class, or specific tests via right-click options.
Open the command prompt in the project root (containing pom.xml) and run mvnw test to execute tests, then review two tests run with zero failures and build success.
Maintain the same package hierarchy in main and test folders, name test classes after the business logic with a trailing test, and keep tests in the test directory.
Learn how to name test methods clearly in JUnit and Mockito with Spring Boot, ensuring inputs, expected outputs, and the tested method are obvious at a glance.
Explore naming test methods with a given-when-then style to reveal inputs and expected outputs, using sums of 3 and 5 equals 8, and 10 and 7 equals 17.
Use the display name annotation to give readable, meaningful names to test cases, making inputs like 3 plus 5 equals 8 and 10 plus 7 equals 17 visible during execution.
Apply display name annotation to customize the test class name, enhancing readability in test reports for JUnit 5 tests like math operations, including addition, subtraction, and division.
Structure the body of test methods with given when then to improve readability, by initializing inputs in given, invoking the method in when, and asserting results in then.
Structure the second test method using given-when-then, initialize inputs (p = 7, expected = 17), call math operations sum(a, b), and assert results; rerun tests to confirm all pass.
Demonstrate displaying execution details of test cases in a JUnit 5 environment by using print statements to show each test's inputs and execution sequence when running the test class.
Illustrates failing tests in a JUnit 5 and Spring Boot project to show the need for descriptive error messages, and guides adding clear expected versus actual value details.
Explore how to display descriptive error messages for failed tests using the three-argument assertEquals, showing actual versus expected like 'three plus five should be equal to eight'.
Convert error-message expressions into lambda expressions in JUnit 5 tests to delay evaluation until tests fail. Boost test suite performance by ensuring these expressions are evaluated only on failure.
Master JUnit 5 and Mockito with Spring Boot through building the is even method tests, using given/when/then, test annotations, and assert true assertions for even and odd inputs.
Develop and verify unit tests for the is even method using assert false for odd inputs, with clear error messages and guidance on fixing failing tests.
Create a string operations class with a reverse method using a string builder to reverse a non-null input of length greater than one, returning the reversed string or null.
Demonstrates creating a JUnit 5 unit test for the string operations reverse method in a basic package, validating non-null inputs and asserting the reversed result.
Write a JUnit 5 test for the reverse method that asserts a valid input yields a non-null string using Assertions.assertNotNull, with a descriptive test display name.
Learn to test invalid inputs for a reverse method that returns null, verifying with assertNull when input is null or has length less than two, via a dedicated test case.
Use multiple assertions in a single test method with JUnit 5 and Mockito with Spring Boot, ensuring not-null and equals checks all pass for the test to succeed.
teaches throwing an illegal argument exception when a not null input string length exceeds 15, with message 'length of input string cannot exceed 15', and includes a reverse method test.
Learn to use JUnit 5 assertThrows with a lambda to verify illegal argument exception when input length exceeds 15, by calling stringOperations.reverse on a 20-character input.
Learn how assertThrows works in JUnit 5 by triggering or omitting exceptions, comparing illegal argument exception with arithmetic exception to demonstrate test outcomes.
Create and throw a custom string operations exception when input is null, by extending runtime exception and passing the message input can't be null to the superclass.
Create a test method test reverse for null input that asserts string operations exception is thrown. Instantiate string operations, call reverse with null input inside assertThrows, and verify exception class.
Assert both the exception class and its message in JUnit 5 tests, using illegal argument exception, getMessage, and multiple assertions within a single test method.
Master how to assert exact exception messages in JUnit 5 tests, fix message text, handle null input leading to string operations exceptions, and verify outcomes with assertEquals and e.getMessage.
This course aims at teaching all concepts of JUnit 5 Testing Framework with Detailed Explanation. Become Expert at Writing Test Cases of all Layers of Spring Boot Code.
This course includes creation of Read World - Industry Level Spring Boot Project containing all the layers of coding - Controller Layer, Service Layer, Entity Layer, Repository Layer, DTO Layer, Custom Exception Layer etc.
This course also includes connecting to Azure Database which includes creation of Resource Group, SQL Server, SQL Database, Creating Admin User etc in Azure.
Learn all these topics and many more with this course:
Create a Spring Boot App
@Test and Assertions
Various ways to Run Test Methods
Structuring Test Method - GIVEN WHEN THEN
Assertion Error Message
Assertions for boolean
Assertions for null
Multiple Assertions in a Test Method
Assertions of Exception
Static Import of Assertions
@Disabled and fail()
Build a Real Time Spring Boot Project
Service Layer Basic Test
@TestMethodOrder
Service Layer Parameterized Test
@ParameterizedTest
@CsvFileSource
@CsvSource
@MethodSource
@TestInstance
@BeforeEach
@AfterEach
@BeforeAll
@AfterAll
Lifecycle Methods
Code Coverage
maven-surefire-report-plugin
Jacoco
Mockito
@Mock
Mockito.when()
Mockito.then()
Mockito.any()
WebMvc - Testing Controller Layer
@WebMvcTest
@MockitoBean
MockMvcRequestBuilders
MockMvc
Testing Entity Layer
@DataJpaTest
TestEntityManager
Testing Repository Layer
Query Methods - @Query
Integration Testing - Testing All Layers Together
@SpringBootTest Annotation with webEnvironment
TestRestTemplate
Azure Database
TDD - Test Driven Development