Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Writing Junit test case for custom component, which is extended from core component

Avatar

Level 3

Hi All,

 

I have a custom hero component, which is extended from Image/v3 core component. The sling model is written using Sling Delegation pattern. I have overridden getSrc() and getAlt() methods in my sling model. 

How do we write Junit test case for these methods specifically ? Are these methods need to be covered, in general?

Any working example is highly appreciated.

 

Many thanks in advance!

 

Best,

Rupal

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @rupaljain2408 
This methods are not covered because they always return null.

If you want to cover just a code coverage, you can cover for null but I don't think so you will be able to test those overriden method.



Arun Patidar

View solution in original post

4 Replies

Hi @Saravanan_Dharmaraj ,

 

Thank you for your reply. I checked this code from @arunpatidar , however he has not covered the core component's methods which were overridden in model class, for example - getActions() , getLinkURL(), getImageResource() etc. 

Do we not have to cover these methods from core component? 

 

Best,

Rupal

Avatar

Correct answer by
Community Advisor

Hi @rupaljain2408 
This methods are not covered because they always return null.

If you want to cover just a code coverage, you can cover for null but I don't think so you will be able to test those overriden method.



Arun Patidar