JUnit and Mockito Unit Testing for Java Developers

Video description

Do you want to get hands-on demonstrations of JUnit and Mockito in action, in a simple no-fluff guide to how unit testing works?

Are you struggling to understand unit testing and would like a friendly guide to help you get it from the ground up?

Maybe you're a junior Java developer who is just starting out and you need a hands-on guide to JUnit and Mockito unit testing to get up and running quickly?

Or you might be an old hand at Java who has been out of practice and needs to level up your unit-testing skills for a new project?

Perhaps you've started a new job where JUnit and Mockito are used to test applications, and you need to get up to speed on the best practices. Or you're learning industry-standard tools to better place you ahead of the competition. Or you just want to ramp up your unit testing knowledge quickly in a no-fuss guide.

Then… this course is for you! It takes you straight from the beginning, and gets you up and running, then fully proficient at writing unit tests using JUnit, Mockito and Hamcrest. It unlocks the mechanics of how JUnit and Mockito work, so you are able to better test your Java projects with the frameworks and have fun doing so!


Distributed by Manning Publications

This course was created independently by Matt Speake and is distributed by Manning through our exclusive liveVideo platform.



About the Technology


About the Video


What's Inside
  • Write unit tests confidently using JUnit
  • Understand mocking and mock objects and how to test interactions with Mockito
  • Use Mockito to create test fixtures and stub methods by programmatic and annotation-driven test setup
  • Analyze production code to guide writing unit tests
  • Learn the JUnit Assertions API
  • Write assertions with Hamcrest, the popular assertions library shipped with JUnit


About the Reader
Basic knowledge of coding in Java

About the Author

Matt Speake is a professional Java software engineer and have been programming for more than 20 years, working everywhere from small startups to large investment banks.

He started JavaEasily in 2018 so he could produce courses focused on teaching Java technology to students all around the world.

Since then he has been busy creating the Java Easily website and publishing courses and articles on different aspects of Java.

Feel free to check out the JavaEasily YouTube channel and follow it on Facebook and Twitter.



Quotes

Table of contents

  1. Introduction
    1. Welcome to the Course!
    2. Overview of the Course Structure
  2. Unit Testing Foundations
    1. Section Introduction
    2. What is Unit Testing?
    3. What is JUnit?
    4. Introducing a Simple Unit Test in JUnit
    5. Structure of a Unit Test
    6. Conventions for Writing Unit Tests
    7. Characteristics of Proper Unit Tests
    8. What are Assertions?
  3. Creating a Java Project which uses JUnit
    1. Section Introduction
    2. Creating a Java project which includes JUnit using Maven Quickstart Archetype
    3. Introducing a typical Java project structure (production vs test source trees)
    4. Understanding basic conventions for creating unit tests (package and naming)
  4. Writing and Running Unit Tests with JUnit and IntelliJ IDEA
    1. Section Introduction
    2. Creating a test method with the @Test annotation
    3. Running a unit test within the IDE and understanding test success
    4. Understanding test failures with exceptions
    5. Failing a unit test explicitly with Assert.fail
    6. Using Assert.fail to check validation logic in a try:catch
    7. An introduction to the JUnit Assertions API
    8. Structuring unit tests with Arrange:Act:Assert
    9. Understanding execution of assertions and JUnit’s fail-fast test failure workin
    10. Adding descriptive comments to assertions and test failures to aid diagnostics
    11. Coding a unit test following Arrange-Act-Assert
    12. Keeping test setup DRY with @Before
    13. Understanding test fixture instantiation
  5. Unit Testing with Mock Objects and Mockito
    1. Section Introduction
    2. What is Mockito and what are Mock Objects?
    3. Introduction to testing with mock objects
    4. Configuring Projects to Use Mockito
    5. Creating a project which uses JUnit and Mockito
    6. Coding a Layered Architecture - Presentation Layer
    7. Coding a Layered Architecture - Business Layer
    8. Coding a Layered Architecture - Persistence Layer
    9. Putting the correct packages in place to respect the layering
    10. Writing a test for the Login Controller in the presentation layer
    11. Understanding the test fixture setup when writing mock object based unit tests
    12. Writing a test for the Authentication Service in the business layer
    13. Thinking about design decisions when unit testing
  6. Looking at the Hamcrest Assertions Library
    1. Section Introduction
    2. Evolving the Domain and Repository Classes
    3. Ignoring Tests with @ignore
    4. Implementing a Finder in the Repository
    5. Implementing Business Logic in the Service
    6. Configuring Maven to use Java 8
    7. Evolving the Repository Class
    8. Adding a Parameter-driven Finder to the Service
    9. Refactoring to Evolve a New Service
    10. Generating Test Methods in the IDE and Toggling Between Production and Test Code
    11. Introducing the JUnit Mockito Runner and @Mock
    12. Analyzing the Production Code to Determine How to Write the Arrange Section
    13. Using Mockito’s @InjectMocks to Create the System Under Test with Dependencies
    14. Keep Yourself Motivated by Checking the Happy Path Test Output
    15. Using the JUnit Assertions API to write the Assert Section
    16. Thinking About the Weaknesses of the JUnit Assertions API
    17. The Importance of Checking Your Work as you Go
    18. Upgrading a JUnit project to use the full Hamcrest version
    19. Replacing JUnit assertions with Hamcrest and using assertions with collections
    20. Understanding and Reading Hamcrest Test Failures
    21. Quick thoughts on Hamcrest individual vs collection Assertions
    22. Don’t invoke unneeded production code in your test classes
    23. Understanding Evaluation of Hamcrest Matchers
    24. Thinking about why we keep production code to a minimum in tests
    25. Creating Complex Hamcrest Assertions with allOf and Property Matchers

Product information

  • Title: JUnit and Mockito Unit Testing for Java Developers
  • Author(s): Matt Speake
  • Release date: December 2022
  • Publisher(s): Manning Publications
  • ISBN: 10000DIVC2022182