AD0-E134 practice question 4 of 15

A developer is on an AEM application that is being used to calculate an employee's salary. The calculation is done in an OSGi service called CalculationService. This service class has a dependency on one other service, called the EmployeeService. How should the developer make sure that the critical code in the CalculationService has a high unit test coverage?

Full set: 72 questions
Answer options
A: Use a mock framework in the unit test to inject the CalculationService
B: Instantiate the EmployeeService in the unit test and pass it to the constructor of the CalculationService
C: Use a mock framework in the unit test to inject the EmployeeService Correct answer
D: Use the feature flag in the unit test to disable the calls to the EmployeeService
Correct Answer:
C. Use a mock framework in the unit test to inject the EmployeeService
Explanation

A mock framework is a tool that allows creating mock objects that simulate the behavior of real objects in a controlled way. A mock framework can be used in a unit test to inject the EmployeeService dependency into the CalculationService and verify its interactions. This way, the unit test can focus on testing the logic of the CalculationService without relying on the actual implementation of the EmployeeService. Reference: https://sling.apache.org/documentation/development/sling-testing-tools.html https://wcm.io/testing/aem-mock/usage.html

Scroll to Top