Java SpringBoot || Writing Test cases for Code Coverage || JUnit || Mockito

Rahul Kapoor 21 Reputation points
2020-12-23T08:47:53.707+00:00

Hello

Brief info about class under Test.
The class will fetch secret, certificate and access token from KeyVault and login.mirosoftonline.com. Also using Corbertura as code coverage tool.
I am trying to write testcases (using Junit, Mockito) for the below classes, but unable to find correct way.

SecretClient
SecretClientBuilder
KeyVaultSecret
ConfidentialClientApplication
ClientCredentialParameters

Some problems I found is as the above classes are marked as final, so unable to Mock. Also if I try to use PowerMock, Corbertura doesnt detect the code covered by it.

Please suggest any alternative way of testing so that my code coverage also gets calculated using corbertura.

Thanks!

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,105 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,844 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,426 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. 2020-12-23T19:01:28.177+00:00

    Hello, you should not need to mock implementations but interfaces, such as IConfidentialClientApplication (implemented by ConfidentialClientApplication). To make your classes (unit) testable you should inject interfaces as dependencies.

    Please let me know if you need more help. If the answer was helpful to you, please accept it and, optionally, provide feedback so that other members in the community can benefit from it.

    0 comments No comments