Unit Testing with Mocks: Getting Started with Mockito

Software Testing    |    Beginner
  • 15 videos | 1h 59m 30s
  • Includes Assessment
  • Earns a Badge
Rating 4.6 of 66 users Rating 4.6 of 66 users (66)
Mockito is a Java framework for building mocks during unit testing. When performing unit tests on an object, you often have other, complex objects that the object under test depends upon. Rather than using those complex objects, you can use Mockito to create mocks of those objects and stub their methods to simulate expected behavior. Use this course to get to grips with mocking and its relationship with unit testing. Set up a Maven project and add the required Mockito and JUnit dependencies. Create mocks of built-in classes, such as the ArrayList, and built-in interfaces, such as the Comparator. Then, work with stub methods using Mockito's when().thenReturn() syntax. When you're done, you'll be able to identify situations where using mocks is a good idea, construct mocks, stub methods in them using Mockito, and use mock objects in unit tests.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Recall how mocks can be used with unit tests
    Recall the benefits of using mockito to mock objects
    Install maven and set up a new project
    Set up intellij with a maven project
    Add dependencies for junit and mockito
    Use the static mock() method to mock objects
    Use the when().thenreturn() syntax to configure behavior
  • Use assertions in test cases
    Configure mocks with the when().thenreturn() syntax with input arguments
    Create mock objects of interfaces
    Sort a treeset using a comparator mock
    Set up a real-world object that can be mocked
    Mock an iterator object
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 1m 52s
  • 10m 19s
  • Locked
    3.  Using Mockito to Mock Objects
    5m 14s
  • Locked
    4.  Creating a New Maven Project
    8m 48s
  • Locked
    5.  Importing a Maven Project into IntelliJ
    7m 15s
  • Locked
    6.  Setting up JUnit and Mockito Dependencies
    9m 43s
  • Locked
    7.  Mocking Objects with the Static mock() Method
    7m 54s
  • Locked
    8.  Stubbing Methods Using when().thenReturn()
    8m 45s
  • Locked
    9.  Using Assertions in Test Cases
    6m 26s
  • Locked
    10.  Stubbing Methods with Specific Input Arguments
    11m 34s
  • Locked
    11.  Mocking Interfaces
    9m 48s
  • Locked
    12.  Creating an Object Depending on a Mock
    11m 33s
  • Locked
    13.  Using Mocks with Objects under Test
    7m 25s
  • Locked
    14.  Mocking Iterators
    10m 43s
  • Locked
    15.  Course Summary
    2m 13s

EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE

Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.

Digital badges are yours to keep, forever.

YOU MIGHT ALSO LIKE

Rating 3.7 of 11 users Rating 3.7 of 11 users (11)
Rating 4.1 of 38 users Rating 4.1 of 38 users (38)
Rating 4.4 of 61 users Rating 4.4 of 61 users (61)

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.4 of 67 users Rating 4.4 of 67 users (67)
Rating 4.8 of 42 users Rating 4.8 of 42 users (42)
Rating 4.7 of 26 users Rating 4.7 of 26 users (26)