Unit Testing with Mocks: Mocking Exceptions & Using Spies
Software Testing
| Intermediate
- 12 Videos | 1h 40m 16s
- Includes Assessment
- Earns a Badge
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 courseconfigure stubs to throw exceptionsthrow exceptions from stubbed methodsthrow exceptions from methods that return voidcreate partial mocks using spiesstub individual methods in spies
-
use spies with interfacesverify interactions with spiesuse the doNothing() function with void methodswork with argument captorstrack input arguments to void methods using argument captorssummarize the key concepts covered in this course
IN THIS COURSE
-
1.Course Overview1m 51sUP NEXT
-
2.Stubbing Methods to Throw Exceptions11m 24s
-
3.Throwing Exceptions from Stubbed Methods9m 30s
-
4.Throwing Exceptions from Void Methods8m 15s
-
5.Creating Partial Mocks Using Spies10m 20s
-
6.Stubbing Individual Methods in Spies11m 25s
-
7.Spying on Interface Objects6m 5s
-
8.Verifying Interactions with Spies in Mockito13m 27s
-
9.Stubbing Methods with Void Return Values11m 17s
-
10.Working with Argument Captors9m 7s
-
11.Tracking Input Arguments Using Argument Captors5m 30s
-
12.Course Summary2m 5s
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion of this course, which can be shared on any social network or business platform
Digital badges are yours to keep, forever.