How to write the JUnit | Community
Skip to main content
Level 6
November 25, 2021
Solved

How to write the JUnit

  • November 25, 2021
  • 2 replies
  • 990 views

For the below code I am unable to write the JUnit for @Postconstruct init()

 

But for text JUNIT is working fine via JSON. Need help

@586265 private Page currentPage; @ValueMapValue Private String text; private String pageTitle; @PostConstruct protected void init() { if(!(currentPage.getName().equalsIgnoreCase("Product") || currentPage.getTemplate.getPath.equals("/conf/we-retail/settings/wcm/templates/hero"))) { text=""; } } public void getText() { return text;}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

you don't need to write the junit for initi method. Amke sure you create 2 json one with your template and another with different template to make code coverage 100%

example

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/main/java/com/aemlab/junit/core/models/OverviewModel.java

https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/test/java/com/aemlab/junit/core/models/OverviewModelTest.java

2 replies

Kiran_Vedantam
Community Advisor
Community Advisor
November 25, 2021
arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 27, 2021
Arun Patidar