Mockito Tutorial: Learn mocking with 25 Junit Examples - Step 13: Mockito Spy

Mockito Tutorial: Learn mocking with 25 Junit Examples - Step 13: Mockito Spy

Assessment

Interactive Video

Information Technology (IT), Architecture

University

Hard

Created by

Quizizz Content

FREE Resource

The video tutorial explains the concept of spies in Mockito, how to create and use them, and their differences from mocks. It covers creating a mock, understanding the functionality of spies, and using spies to track method calls. The tutorial also discusses when to use spies versus mocks, emphasizing that spies are more suitable for legacy systems where code access is limited.

Read more

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the primary purpose of using a spy in Mockito?

To completely replace the functionality of a class

To simplify the code structure

To track method calls while retaining original functionality

To enhance the performance of a test

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the default behavior of a mock in Mockito?

It performs the actual method logic

It logs the method call

It returns a default value

It throws an exception

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you change the return value of a method in a mock?

By using the 'modify' method

By using the 'replace' method

By using the 'stub' method

By using the 'override' keyword

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a key difference between a mock and a spy?

A spy replaces all methods, a mock does not

A spy can track method calls, a mock cannot

A mock can track method calls, a spy cannot

A mock retains original functionality, a spy does not

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In what scenario is it more appropriate to use a spy instead of a mock?

When you need to test a new feature

When you want to track method calls in a legacy system

When you want to improve test performance

When you need to simplify the code

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens when you add an element to a spy of an ArrayList?

An exception is thrown

The size of the list increases

The size of the list remains unchanged

The list is cleared

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you verify that a method was never called on a spy?

By using the 'check' method

By using the 'verify' method with 'never'

By using the 'assertNever' method

By using the 'confirm' method

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?