Unit Testing with Mocks: Mocking Exceptions & Using Spies

Software Testing    |    Intermediate
  • 12 videos | 1h 40m 16s
  • Includes Assessment
  • Earns a Badge
Rating 4.6 of 18 users Rating 4.6 of 18 users (18)
Unlike a mock, which has no real state, and in which all behavior must be stubbed, a spy is built atop a real object of the class being mocked and has almost full functionality. Only specific methods of the spy are stubbed, which is useful if it is too complex or cumbersome to mock. Use this course to learn how to identify when spies are a better choice than mocks, how to construct spies and stub specific methods, and how to raise exceptions in stubbed methods of your mocks. Then, use different methods to check how the object under test copes with those exceptions. Moving on, learn how to stub void methods and when to make use of the doNothing().when() syntax. When you're done, you'll be able to correctly use spies, mock exceptions and test their handling, mock void methods, and use argument captors.

WHAT YOU WILL LEARN

  • Discover the key concepts covered in this course
    Configure stubs to throw exceptions
    Throw exceptions from stubbed methods
    Throw exceptions from methods that return void
    Create partial mocks using spies
    Stub individual methods in spies
  • Use spies with interfaces
    Verify interactions with spies
    Use the donothing() function with void methods
    Work with argument captors
    Track input arguments to void methods using argument captors
    Summarize the key concepts covered in this course

IN THIS COURSE

  • 1m 51s
  • 11m 24s
  • Locked
    3.  Throwing Exceptions from Stubbed Methods
    9m 30s
  • Locked
    4.  Throwing Exceptions from Void Methods
    8m 15s
  • Locked
    5.  Creating Partial Mocks Using Spies
    10m 20s
  • Locked
    6.  Stubbing Individual Methods in Spies
    11m 25s
  • Locked
    7.  Spying on Interface Objects
    6m 5s
  • Locked
    8.  Verifying Interactions with Spies in Mockito
    13m 27s
  • Locked
    9.  Stubbing Methods with Void Return Values
    11m 17s
  • Locked
    10.  Working with Argument Captors
    9m 7s
  • Locked
    11.  Tracking Input Arguments Using Argument Captors
    5m 30s
  • Locked
    12.  Course Summary
    2m 5s

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.

PEOPLE WHO VIEWED THIS ALSO VIEWED THESE

Rating 4.6 of 363 users Rating 4.6 of 363 users (363)
Rating 4.6 of 66 users Rating 4.6 of 66 users (66)
Rating 4.8 of 42 users Rating 4.8 of 42 users (42)