
Install the latest JDK, download it from Oracle, install Spring Tool Suite for Eclipse, and configure STS to use the Java SE JDK home directory.
Create multiple projects from scratch using JUnit, Mockito, and PowerMock, then download and study the provided project zip for reference while building each project.
Kick off this JUnit and Mockito crash course by exploring its sectioned structure and startup setup, enjoy self-paced quizzes for self-check, then practice writing unit tests and asking questions.
Master unit testing by validating public methods with varied inputs, handling positive and exception scenarios, and using JUnit with Mockito to mock dependencies for fast, isolated tests.
Understand what a unit testing framework is. Write a Java class and test it with the JUnit API, covering positive and exceptional cases and initializing test data or objects.
Explore how JUnit provides an easy to use api to write tests, assert the actual results against the expected results, and run and report outcomes with a developer friendly framework.
Set up an Eclipse Java project with a test folder, implement a greeting interface and greetingimpl, and write a JUnit test using assertNotNull and assertEquals.
Learn to test exception scenarios in JUnit by validating null or blank names and throwing illegal argument exception, using @Test(expected = IllegalArgumentException.class) to cover each case.
Learn to use the @Before and @After annotations to initialize data required for each test and to cleanup after each test method in the JUnit and Mockito crash course.
Join the JUnit and Mockito crash course to explore JUnit 5's modular platform, vintage support for JUnit 4, Java 8 features, and Maven-based dependency setup.
Maven automates building, testing, packaging, and deployment of Java projects using convention over configuration, with a standard folder layout (src/main/java, src/main/resources, src/test/java, src/test/resources), archetypes, and IDE support.
Create a maven project in Eclipse, add JUnit 5 dependencies (JUnit Jupiter engine and Vintage engine) to pom.xml, set the compiler to 1.8, and migrate tests to JUnit 5.
Migrate to JUnit 5 by switching imports and adopting JUnit Jupiter annotations such as before each and after each, with updated assertions.
Master how to assert exceptions in JUnit using assertThrows with the expected exception and a lambda executable, while removing the deprecated test attribute and testing illegal argument scenarios.
Run JUnit 5 tests in Eclipse by right-clicking a test and choosing run as JUnit test, or enable support by adding JUnit platform runner and JUnit Jupiter API to pom.xml.
Build a Maven project, run tests automatically, and generate a jar in the target directory. Run Maven install to compile sources, execute tests, and produce artifacts with sure fire reports.
Learn to run tests with both JUnit 4 and JUnit 5, using a Maven project, proper dependencies, and JUnit annotations, so Mockito tests behave as expected.
Explore using JUnit and Mockito in a Maven project by importing an Order Processing Service Maven project into Eclipse IDE, examining the POM.xml, and writing a unit test from scratch.
Download and unzip the order processing service, import as a maven project in Eclipse, configure pom.xml dependencies for JUnit 5 and Mockito to test the bo and dao layers.
Walks through the data access layer, detailing the order dao interface with CRUD methods, the dummy dao impl, and how to mock it with Mockito for bo layer testing.
Learn how mocking enables unit testing by isolating a unit from its dependencies, using mock objects, stubbing, and verifying with Mockito. Follow the three steps: stubbing, setting expectations, and verifying.
Launch unit testing for the order bo impl by mocking its order dao with Mockito and JUnit Jupiter, stub createOrder to return 1, then verify and assert true.
test the negative scenario where the dao returns zero, asserting that place order yields false, by using Mockito to stub dao.createOrder and verify invocation in a JUnit test.
Stub the dao create order to throw a SQL exception during the place order flow and assert a bo exception is thrown.
Test the cancel order method in a JUnit and Mockito environment by stubbing dao read and update calls, asserting results, and verifying interactions.
Test the negative cancel order scenario by simulating dao update returning zero, causing the cancel order to return false. Refactor magic numbers into constants and verify tests remain green.
Explore exception handling in JUnit tests by simulating sql exceptions during read and update when canceling an order, and asserting bo exceptions with a mock dao layer.
Learn what code coverage is and why it matters to developers, architects, and management; install the ECLEmma plug-in for Eclipse, measure coverage by running tests, and improve test coverage.
Learn how test coverage measures which source lines are executed by unit tests, identify gaps, and use tools like JaCoCo, Cobertura, and EclEmma within CI pipelines.
Install the open source EclEmma code coverage plugin for Eclipse via the Eclipse marketplace, then restart Eclipse to apply and access coverage from the Run menu, version 2.3.2.
Learn to measure Java test coverage with the ECLEmma plugin in Eclipse, run tests, and interpret coverage reports to identify untested methods such as delete order and get DAO.
Boost test coverage from 71% to 84.1% by adding a JUnit test for delete order, refactoring 123 to a constant, and verifying DAO.delete is called with the order id.
Explore the Mockito API that powers most unit tests in typical projects. Learn how to expand your testing skills as the course updates this section with ongoing improvements.
Learn to use Mockito's verify to confirm mocked object methods are called, experimenting with times and at least verification modes, and understand how verification modes affect test outcomes.
Explore how Mockito matchers simplify stubbing and verification, using any int and other matchers to handle inputs without creating full objects.
Set up the Mockito scrapbook Maven project in Eclipse, import JUnit and Mockito dependencies, and prepare to test class A by mocking B’s void method.
Learn to stub and verify void methods with Mockito in JUnit, creating mocks for class B, initializing mocks in setup, and verifying the void call on B.
Learn to explicitly stub void methods in JUnit and Mockito using the do-nothing method from the Mockito api, with the syntax do nothing when a void method is called.
Learn to stub consecutive void calls in Mockito with doNothing and doThrow, making the first call do nothing and the second throw an exception, with test verification.
Learn the F.I.R.S.T principle for agile software testing, ensuring fast, independent, repeatable, self-validating, and timely unit tests to deliver quick feedback across environments.
Explore test doubles and the five patterns—dummy, stubs, mocks, fake, and spies—and learn how they mock actual objects to write robust unit tests in Mockito.
Explore test doubles in Mockito, including dummies, stubs, mocks, fakes, and spies, and learn to stub methods, throw exceptions, and verify interactions.
Explore partial mocking with a Mockito spy to reuse real methods while stubbing selective behavior, including using doReturn with a spy and contrasting with when, in a practical list example.
Understand spy versus mock in Mockito: spies use the real object unless stubbed, while mocks are library objects, and use when syntax to stub or call real methods when needed.
Download the Maven project, import it into Eclipse, install Tomcat 9, run the simple Java web app with a coupon servlet, two jsp pages, and JUnit/Mockito tests.
Create unit tests for a servlet by mocking http servlet request, response, and request dispatcher with Mockito, generating doGet and doPost tests and running them as JUnit tests.
Test the doGet method by mocking response.getWriter with a PrintWriter wrapping a StringWriter, using Mockito to verify the captured output with an assertion in a JUnit test.
Test the doPost method by mocking the request and dispatcher, invoking the coupon servlet's doPost with a mocked request and response, and verifying that request.setAttribute('discount','Super sale') and forward are called.
Learn how parameterized JUnit tests in JUnit 4 run a test method against multiple data sets, using a constructor, a static data method, and the parameterized runner to verify results.
Download the calculator maven project, review the latest JUnit upgrades, and verify the add method returns 30 for 10 and 20, with a simple calculator implementation; next, learn parameterized tests.
Create a static data set method that returns a collection of integer arrays to feed a JUnit parameterized test, annotated with the @Parameters annotation, mapping num1, num2, and result.
Update existing tests to use parameterized values, mark the test class with the parameterized runner, and verify multiple data sets yield expected results, showcasing parameterized testing in JUnit.
Demonstrates the parameterized test flow in junit, where a static method marked with @parameters provides datasets for the parameterized runner to instantiate the test class and inject values.
Sample of the reviews:
Very good teacher, knows the material. Hands on exercises that are quick to write, but very useful to support the learning of the course content. I'll keep these tiny projects and I'll refer to it often when coding. I've learned a lot about JUnit testing and Mockito, but also about other tools useful in software unit testing: Ex: Spring, shortcuts in Eclipse. - Guy Audet
Very well explained, to the point, on short interval to grasp the content. Every lecture has purpose achieved. Simple examples. Really nice course. - Kaushal Trivedi
I enjoyed the course. The Course is well structured, principles were clearly explained, the sound and picture quality was good. I recommend the course to everyone who would like to begin with java unit testing. Thanks, Bharath! - Mario Banay
---
Are you a java developer who want to become an expert at Unit Testing ? Then this course is a quick practical guide for you. Learn how to write real unit tests using JUnit and Mockito. This course will simplify things with concepts and step by step implementations .
There are so many java professionals who write great code , but not unit tests. This course aims at filling that gap by covering JUnit and Mockito the two required frameworks to write good unit tests.
Learn and master the most popular unit testing technologies in this comprehensive course.
Understand the importance of writing Unit Tests
Updated to use the latest versions of JUnit and Mockito
Learn the Syntax of JUnit 4 and 5
Demystify the topics of Mocking
Write Unit tests using JUnit and Mockito
Learn what test coverage is and how to measure it
Run unit tests as a part of your Maven build
Learn how to Unit Test Spring Boot Applicaiton
All in easy steps
Mastering Unit Testing for Java Professionals:
JUnit is a open source Framework to test and assert code behavior . Mockito mocks out the dependencies and stub the expectations allowing testing a particular layer/unit in isolation.
Any java developer at any level can access the key lessons and concepts in this course and learn to write quality unit tests.
This course is perfect for every java developer who works on building high quality applications .
Contents and Overview:
In over 4 hours of lectures this course covers necessary JUnit API and its usage with Mockito.
This course covers the importance of unit testing , how to effectively use JUnit ,how mocking works and how to use Mockito to write real unit tests.
Up on completion you will be able to test Java and Spring Boot applications ,run unit tests as a part of your build and measure code coverage and improve it.