question

RahulKapoor-7882 avatar image
0 Votes"
RahulKapoor-7882 asked ·

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

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-webappsazure-key-vaultazure-ad-msalazure-ad-libraries
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

alfredorevilla-msft avatar image
0 Votes"
alfredorevilla-msft answered ·

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.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.