
Explore Spring Boot unit testing with JUnit, Mockito and MockMvc to improve code design and reliability. Learn to test Spring MVC web apps and REST APIs with Maven and IDEs.
Discover unit testing basics, automate with JUnit and Mockito, build a battery of tests with mocks and stubs, and enable reproducible CI/CD workflows in IDEs.
Explore the fundamentals of JUnit unit testing with simple add method examples, covering test setup, execution, assertions, Maven dependencies, and running tests.
Learn how to use JUnit assertions like assert equals, assert not equals, assert null, and assert not null, with static imports and examples to verify expected results.
Install starter code and set up the Maven JUnit Jupiter dependency in the Spring Boot unit testing project, then reload Maven to finalize test-scoped additions.
Learn to set up a test package, write unit tests in a non-public test class, validate equals, not equals, and null checks, and run tests using JUnit assertions.
Learn how JUnit lifecycle methods manage per-test setup and cleanup with @BeforeEach and @AfterEach, and how @BeforeAll and @AfterAll run once before and after all tests.
Explore unit test lifecycles with before each, after each, before all, and after all. See demo utils setup and diagnostic prints for equals, not equals, and null checks.
Learn how to customize JUnit display names in Spring Boot unit tests using display name annotations and generators for clearer reports for managers and non-techies.
Learn how to define and customize display names in JUnit tests for Spring Boot projects, using display name generators, underscores vs camel case, and practical examples with before/after hooks.
Explore JUnit assertions for same and not same object references and for true and false conditions, using assertSame, assertNotSame, assertTrue, and assertFalse within Spring Boot unit tests.
Learn to use JUnit assertions for same/not same and true/false, illustrated by testing DemoUtils methods like isGreater and object references.
Explore JUnit assertions for arrays, iterables, and lines, including assertArrayEquals, assertIterableEquals, and assertLinesMatch, with deeply equal checks and demos using DemoUtils and academyInList.
Demonstrates using JUnit assertions for array, iterable, and lines, including assertArrayEquals and assertLinesMatch, to verify deep equality of string arrays and lists in unit tests.
Learn JUnit assertions for throws and timeouts, using assertThrows and assertDoesNotThrow with lambdas to test negative inputs, and assertTimeoutPreemtively to ensure methods like checkTimeout finish within three seconds.
Learn to validate exception handling with JUnit assertions by testing throws and does-not-throw scenarios using assertThrows and a lambda that calls DemoUtils.throwException, including negative and positive inputs.
Demonstrate using JUnit assert timeout to enforce a three-second limit on a timeout check, showing how two seconds passes and five seconds fails, with lambda-based test code.
Explore how to control junit test execution order with @TestMethodOrder and order annotations, choosing display name, method name, or random order, while keeping tests independent and noting deterministic defaults.
Explore ordering JUnit tests using MethodOrderer strategies, switching from method name to display name, and applying OrderAnnotation with priority values to control test execution.
Discover code coverage and test reports in IntelliJ, learn how coverage percentages and method-level results are shown, and explore HTML exports for DevOps build status pages.
Learn to run tests with coverage in IntelliJ, generate and view coverage reports, interpret green/red indicators, and increase coverage by adding tests for untested methods.
Learn to run unit tests with Maven from the command line, generate HTML test reports and code coverage, and view failed tests with the Surefire and Site plugins.
Generate code coverage reports with the Jacoco Maven plugin by running mvn clean test, then view the Jacoco index.html report to see covered and missed methods.
Cover code coverage and test reports with Maven, delete old coverage and unit test result folders, and run tests from the command line using mvn clean test.
Add the Maven Surefire report plugin and the Maven site plugin to your pom.xml. Run mvn site to generate the HTML surefire.html unit test report from the command line.
Generate code coverage reports with the Jacoco Maven plugin for Spring Boot unit testing, preparing the Jacoco agent and running the test phase to produce the report at target/site/jacoco/index.html.
Explore conditional tests in Spring Boot unit testing, using disabled and enabled on OS annotations, plus system property and environment variable conditions to selectively run tests and report status.
Demonstrate using @Disabled and @EnabledOnOs to run tests conditionally on Windows, Mac, and Linux, with a disabled test explained by a Jira reason in a Spring Boot unit testing course.
Enable tests conditionally with @EnabledIfEnvironmentVariable and @EnabledIfSystemProperty, configuring IntelliJ run configurations to activate dev environment tests when env vars or system properties match, ensuring selective test execution.
Explore test-driven development by starting with a failing test, writing code to pass, and refactoring in a continuous loop, using FizzBuzz as a practical example.
Set up test and main packages under com.luv2code.tdd, create FizzBuzzTest, write a failing test for visible by 3, use JUnit annotations and orderer, run tests, and prepare for refactoring.
Learn test driven development by building a FizzBuzz class with a compute method, using modulus to return Fizz for multiples of three and Buzz for multiples of five.
Practice test-driven development by implementing FizzBuzz logic in a Spring Boot unit testing context, updating tests for divisible by three and five, and both, then ensuring all tests pass.
Refactor the fizzbuzz implementation within a test-driven development loop, using a string builder to append fizz or buzz when divisible by three or five, then run tests.
Explore parameterized tests in JUnit using value source, CSV source, CSV file source, enums, and method source to run the same test with multiple inputs.
learn to create parameterized tests using a csv data file in a resources directory to drive FizzBuzz validations with JUnit parameterized tests.
Demonstrates parameterized testing in spring boot with csv data files for fizzbuzz, using medium and large data sets (1–50 and 1–100) and a project rebuild to load resources.
Develop a main application in Java to print the first 100 FizzBuzz numbers using a for loop and the FizzBuzz.compute method, validating changes with unit tests and TDD.
Explore spring boot unit testing with the spring boot test annotation, which loads the application context, enables dependency injection, and supports mock objects for web data and REST APIs.
Open the starting spring boot project, review the student models and grades, and note bean and properties setup as you prepare to build unit tests for this code base.
Add the Spring Boot Starter Test artifact with test scope to enable JUnit five, verify with mvn dependency tree, and set up a test directory with Spring Boot test annotations.
Read application.properties in a Spring Boot test with @Value, inject beans such as college student and student grades, and run a before-each initialization to print diagnostics and verify properties.
Demonstrates Spring Boot unit testing with JUnit using assertEquals and assertNotEquals to validate grade calculations, including a correct 353.25 result and a deliberate failure to verify tests break and recover.
Demonstrate unit testing with assertTrue, assertFalse, and assertNotNull by validating grade comparisons, false conditions, and null values in sample tests.
Explore spring boot unit testing with JUnit, Mockito and MockMvc by validating prototype beans, autowiring the application context, retrieving new bean instances, and computing grade point average with assertAll.
Mock with Mockito and Spring Boot to test a service in isolation using a test double for the Dao, simulating mock responses and verifying method calls.
Master the mocking workflow with Mockito by creating a DAO mock, injecting it into the service, setting when-thenReturn expectations, calling the method under test, asserting results, and verifying calls.
Set up a spring boot project with a dao and service, wiring them via autowired beans. Use spring boot starter test and Mockito to verify dao delegation.
Create a mock for the DAO using @Mock, inject it into the service with @InjectMocks, and initialize test data in a before each method.
Learn how to use Mockito to set expectations, call the service under test, assert results, and verify DAO method invocations, including times verification, in a Spring Boot unit test.
Learn how to use the Spring Boot Mockito bean annotation to inject mocks and regular beans, replacing the limitations of mock and inject mocks with automatic wiring.
Learn to replace Mockito mocks with a Spring Boot mock bean, inject mocks via the application context, and run GPA tests with autowired dependencies.
Write a new unit test for not null behavior using Mockito, set up the mock to return true when applicationDao.checkNull, assertNotNull on the app service, and confirm the test passes.
Configure mocks to throw exceptions and test exception handling in Spring Boot tests, using when-then-throw on the application dao, with consecutive calls, first-call errors, and subsequent returns.
Set up a test to throw a runtime exception when a mocked method is called, and verify the application service delegates to the DAO while handling single and consecutive calls.
Learn how to test non-public fields and methods using Spring's ReflectionTestUtils, including reading and setting private fields and invoking private methods, with guidance on when to use it.
Add a private id field to CollegeStudent, generate getters and setters, and a private method returning first name and id; create ReflectionTestUtilsTest to test private field and method via reflection.
Demonstrates using Spring Boot test annotations and a BeforeEach setup to initialize a student object, then directly set private fields like id and student grades to illustrate reflection test utils.
Explore using ReflectionTestUtils to access private fields and ReflectionUtils to invoke private methods in unit tests, such as reading a student's id and calling get first name and id.
Build a Spring Boot grade book app with database persistence, DAO and service layers, tracking history, math, and science grades, and cover unit and integration testing.
Explore the Spring Boot project by reviewing the maven pom.xml, Thymeleaf views, JPA entities, and templates, and set up for upcoming unit and integration testing.
Demonstrate test driven development by creating a failing test in the student and grade service, wiring in studentService and studentDAO with an H2 in-memory database.
Create a Spring service and repository to save a new CollegeStudent via a StudentAndGradeServiceTest, using @Service, @Transactional, a StudentDao extending CrudRepository, and autowiring.
Uncomment and wire the student dao, add findByEmailAddress, and rely on Spring Data JPA to auto-query the embedded H2 database. Run the tests to confirm the email match.
Perform database integration testing with before and after hooks to initialize sample data, run tests, and clean up by deleting data and resetting the primary key to a known state.
Set up sample data with a JDBC template before each test to enable database integration testing. Clean up data and reset the database to a known state.
Develop a delete student test by retrieving a student, deleting by id, and verifying the student is no longer present, then implement the delete method in the service.
Review the application.properties database configuration by inspecting URL, driver, username, and password; note datasource initialization mode always, ddl-auto create-drop, and use the H2 dialect with jpa.show-sql.
Write a unit test to fetch all students via get gradebook, collect them, and assert the size equals one with one student seeded before the test.
Seed the test database with four students using an insertData.sql loaded by @Sql, so BeforeEach adds one more for a total of five.
Explore testing Spring MVC web controllers with MockMvc, crafting HTTP requests and verifying status, view names, and model attributes without a server.
Develop a test setup for Spring MVC web controllers by configuring MockMvc, Spring Boot Test, and a JDBC template, with mocks for services.
Create and validate unit tests by building sample student objects, mocking the grade service to return a college student list, asserting list equality, and wiring the controller for web testing.
Use mockMvc to perform a get request to the gradebook controller, assert status ok, and verify the model and view returns the index view.
Demonstrate test-driven development by posting to gradebook controller to create a student, validate persistence with the dao, and iterate from a failing test to a green one using mock mvc.
Add a post mapping in the gradebook controller to create a student, wire the DAO, and verify the new student is persisted in the database through the service.
Update the gradebook UI to submit new students to the backend and render the updated list by looping over the students model attribute; rename GradebookControllerTest.java mock to studentCreateServiceMock.
Run the Spring Boot MVC app, uncomment dynamic Thymeleaf code, and update the UI to add and retrieve students via the backend controller and database.
Learn to delete a student in a Spring MVC app using test-driven development, mockMvc, and a grade book controller while validating deletion with unit tests.
Learn to test Spring MVC delete operations with MockMvc, asserting an error page when deleting a non-existent student, and implement a pre-delete existence check to pass a failing test.
Apply TDD to implement grade tracking for students by updating the StudentAndGradeService and adding math, science, and history grade DAOs, driving development with failing tests.
Practice test-driven development in spring boot by adding a science grades DAO, writing tests first, injecting dependencies, and validating inserts via JUnit and MockMvc.
explore testing history grade services in a spring boot mvc app by running unit tests that validate grade inserts for math, science, and history.
Verify that the Spring Boot MVC grade service returns false for invalid inputs, including out-of-range grades, unknown student IDs, and unsupported subjects, using JUnit assertions in unit tests.
insert and clean up sample data for math, science, and history grades using beforeeach and aftereach, then run tests to confirm all pass with green checks.
Refactor the grade service test for a Spring Boot MVC app to verify exact grade counts. Cast the iterable to a collection and use size to confirm two grades.
Apply test-driven development to implement delete grade functionality in a Spring Boot MVC app, focusing on the backend math grades via the service and dao, returning the student id.
Implement delete grade functionality for science and history in Spring Boot MVC tests, copying from math, running tests, fixing failures, and achieving green checks that confirm functionality is in place.
Test deleting a grade in a Spring Boot MVC app by handling edge cases with non-existent student ids: invalid grade id and invalid subject; assert zero as the result.
Enhance the delete student unit test by also removing math, science, and history grades and updating daos with delete by student ID, validating red to green test results.
Applies test-driven development to add the backend method studentInformation(1) that retrieves a student's name, email, and grades, starting with a failing test and asserts before implementation.
Retrieve the student from the database, gather math, science, and history grades, convert iterables to lists, and package the data into a GradebookCollegeStudent for the test to pass.
Develop and verify a unit test for retrieving non-existent student information in a Spring Boot MVC app. Fix by adding an existence check that returns null, making the test pass.
Move hard-coded SQL in tests to application.properties and inject it with @Value, then refactor before-each and after-each to use properties for sample data.
Add sql scripts to application.properties to create a student and grades (math, science, history) and delete them later. Use backslashes to compose a single sql string.
Inject SQL into unit tests with the value annotation, mapping properties to test fields and executing statements like 'SQL add student' in the student in grade service test.
Refactor spring boot unit tests by replacing hard-coded sql with variables and loading scripts from application properties, then fix a typo to run all gradebook controller tests successfully.
Spring Boot is the most popular framework for building enterprise Java applications. Spring Boot includes testing support to develop unit tests and integration tests using JUnit, Mockito and MockMvc. By developing tests, you can create applications with better code design, fewer bugs, and higher reliability. This course shows you how to take full advantage of Spring Boot's testing support.
You will also use modern development tools such as IntelliJ (free version) and Maven. All of the projects are based on Maven, so you are free to use any IDE tool that you want.
---
In this course, you will get:
- All source code is available for download
- Responsive Instructors: All questions answered within 24 hours
- PDFs of all lectures are available for download
- Professional video and audio recordings (check the free previews)
- High quality closed-captions / subtitles available for English and 14 other languages (new!)
---
Over 3,000+ Reviews!
- (the most reviews for any Spring Boot Unit Testing course on Udemy, nearly DOUBLE the nearest competitor)
Students love this course! 5-star reviews
Chad Darby and Eric Roby are great at delivering the materials and giving good real-world examples of concepts. they make the course a very enjoyable class, This course is very thorough and detailed. Thank you - Ninos
Great course, the material is explained in such a clear way. I enjoy it a lot. Highly recommendable. - Ardak Sydyknazar
Chad Darby's courses are the best on Udemy. Thanks him I've got my first work and got promotion on the second one. Good job, my friend! (c) :) - Andrii Hryhoriev
this is my 4th Course with Mr. Darby, and his courses are so special. Organized, clear concepts, amazing material. and the most important his Knowledge of the Topic and he really deliver the information's for us. just amazing. - Ra'ed Abu Sa'da
---
In this course, you will learn how to:
JUnit
Develop JUnit Tests
Set up projects to use JUnit
Apply JUnit assertions: Equals/Not Equals and Null/NotNull
Apply JUnit assertions: Same/Not Same and True/False
Leverage JUnit lifecycle annotations
Define custom display names for JUnit tests
Check for exceptions and timeouts
Define execution order in JUnit tests
Perform code coverage analysis for JUnit tests
Apply conditionals with JUnit tests
Test Driven Development (TDD)
Apply Test Driven Development for build tests and application code
Create a failing test first
Update your code to make the tests pass
Take your tests from RED to GREEN
Apply TDD to a coding project
Leverage parameterized tests with TDD
Spring Boot Unit Testing Support
Explore annotations for Spring Boot Unit Testing support
Apply the @SpringBootTest annotation
Read Spring Boot application properties and inject values using the @TestPropertySource annotation
Perform assertEquals and assertNotEquals
Leverage Spring Boot singleton beans and prototype beans
Mocking with Mockito
Identify the need for mocking during test development
Leverage Mockito in JUnit tests
Applying the @MockitoBean annotation for injection (new in Spring Boot 3.4)
Throwing exceptions with Mocks
Spring Reflection Utils
Identify use cases for applying reflection in your JUnit tests
Apply ReflectionTestUtils to access non-public fields and methods
Integrate Spring Reflection Utils in your JUnit tests
Database Integration Testing
Identify the need for database integration testing during test development
Add database setup and clean code using @BeforeEach and @AfterEach
Leverage an embedded database to ease with testing setup and maintenance.
External SQL statements using @Sql annotation
Testing Spring Boot MVC Web Apps with MockMvc
Apply Spring Boot using testing for a Spring MVC CRUD web app
Identify use cases for testing Spring MVC @Controller
Configure the JUnit test case using @AutoConfigureMockMvc
Inject the MockMvc dependency for testing Spring MVC Controllers
Send HTTP Requests to Spring MVC Controllers and assert the results
Assert the view name returned by the Spring MVC Controller
Assert model attributes for the desired values
Testing Spring Boot REST APIs with MockMvc
Apply Spring Boot using testing for a Spring REST CRUD API
Inject the MockMvc dependency for testing Spring MVC @RestController
Send HTTP Requests to Spring MVC @RestController and assert the results
Leverage Jackson Object Mapper to send JSON data to REST API endpoint
Expect successful response and desired content type
Apply JsonPath to verify contents of JSON response
Compared to other Spring Boot Unit Testing courses
This course is up to date and covers recent versions of Spring Boot 3. We make use of modern development tools such as IntelliJ (free version) and Maven.
We are very responsive instructors and we are available to answer your questions and help you work through any problems.
Finally, all source code is provided with the course along with setup instructions.
Student Reviews Prove This Course's Worth
Those who have reviewed the course have pointed out that the instruction is clear and easy to follow, as well as thorough and highly informative.
Many students had also taken other Spring Boot Unit Testing courses in the past, only to find that this Spring Boot Unit Testing course was their favorite. They enjoyed the structure of the content and the high quality audio/video.
Sample of Student Reviews - 5 stars!
Chad Darby and Eric Roby are great at delivering the materials and giving good real-world examples of concepts. they make the course a very enjoyable class, This course is very thorough and detailed. Thank you - Ninos
Great course, the material is explained in such a clear way. I enjoy it a lot. Highly recommendable. - Ardak Sydyknazar
Chad Darby's courses are the best on Udemy. Thanks him I've got my first work and got promotion on the second one. Good job, my friend! (c) :) - Andrii Hryhoriev
this is my 4th Course with Mr. Darby, and his courses are so special. Organized, clear concepts, amazing material. and the most important his Knowledge of the Topic and he really deliver the information's for us. just amazing. - Ra'ed Abu Sa'da
Quality Material
You will receive a quality course, with solid technical material and excellent audio and video production. I am a best-selling instructor on Udemy. Here's a list of my top courses.
Full Stack: React and Spring Boot
Full Stack: Angular and Spring Boot E-Commerce Website
Spring and Hibernate for Beginners
Hibernate: Advanced Development Techniques
Deploy Spring Boot 4 Apps Online to Amazon Cloud (AWS)
JSP and Servlets for Beginners
JavaServer Faces (JSF) for Beginners
These courses have received rave 5 star reviews and over 900,000 students have taken the courses. Also, these courses are the most popular courses in their respective categories.
I also have an active YouTube channel where I post regular videos. In the past year, I’ve created over 1200 video tutorials (public and private). My YouTube channel has over 7 million views and 43k subscribers. So I understand what works and what doesn’t work for creating video tutorials.
No Risk – Udemy Refund
Finally, there is no risk. You can preview 25% of the course for free. Once you purchase the course, if for some reason you are not happy with the course, Udemy offers a 30-day refund (based on Udemy's Refund Policy).
So you have nothing to lose, sign up for this course and learn how to apply Spring Boot Unit Testing
Target Audience
Java Developers with Spring Boot experience