Writing Junit test case for custom component, which is extended from core component | Community
Skip to main content
rupaljain2408
Level 3
Mar 7, 2023 4:12 PM UTC
Solved

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Mar 8, 2023 2:42 PM UTC

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

4 replies

Saravanan_Dharmaraj
New Participant
Mar 7, 2023 6:10 PM UTC
rupaljain2408
Level 3
Mar 8, 2023 12:07 PM UTC

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

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Mar 8, 2023 2:42 PM UTC

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.

Translate
Arun Patidar