5910 Breckenridge Pkwy Suite B, Tampa, FL. 33610
(800) 272-0707

SkillSoft Explore Course

Aspire     Javanista to Java Master     Javanista to Java Master Track 1: Unit Testing
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.

Objectives

Unit Testing with Mocks: Mocking Exceptions & Using Spies

  • 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