Unable to inject a service in junit test cases to test a sling model (having an injection of service using @OSGiService annotation)

Avatar

Avatar
Boost 1
Level 1
HKesani
Level 1

Like

1 like

Total Posts

1 post

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
HKesani
Level 1

Like

1 like

Total Posts

1 post

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
HKesani
Level 1

11-11-2019

Hi All,

I recently started using AemMocks and am still exploring. In one of the requirements, Sling models are implemented all looks fine till now. I started unit testing the same using Aem Mocks.

Problem:

I am unable to inject the service reference into the test class using 'context.registerInjectActivateService'.I have gone through numerous reference documents online but nothing is helpful.

any help is appreciated.

Thanks,

Harshith.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

136 likes

Total Posts

185 posts

Correct reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

136 likes

Total Posts

185 posts

Correct reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile
ArpitVarshney
MVP

11-11-2019

Hi HKesani,

Could you please give a try to below code to mock OSGi service?

1852742_pastedImage_1.png

Reference: https://wcm.io/testing/aem-mock/usage.html#Registering_OSGi_service

Regards,

Arpit Varshney

Answers (0)