Hii, I am using assertEquals(expected, actual ) but when I run my test case my actual value was showing as null.
Error:
Sling Model:
Views
Replies
Total Likes
I don't see the getDescription() method in your sling model. Seems to me either case of missing method or wrong naming convention in JUnit test cases.
Thanks,
Pallavi Shukla
Sorry I post the wrong image of sling model this is the correct one
Hi, @Prachi_Mathur ,
Could you please share your JUnit code? or otherwise try the below approach. I use the same approach for JUnit test cases. I modified my code as per your model screenshot.
import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; import org.apache.sling.api.resource.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith({AemContextExtension.class, MockitoExtension.class}) class AboutModelTest { private final AemContext aemContext = new AemContext(); private About about; @BeforeEach void setUp() { aemContext.addModelsForClasses(About.class); aemContext.load().json("/com/mySite/core/models/about.json", "/component"); Resource resource = aemContext.currentResource("/component/about"); about=aemContext.request().adaptTo(About.class); } @Test void testGetEmail() { final String expected = "abc@gmail.com"; assertEquals(expected, about.getEmail()); } @Test void testGetAddress() { final String expected = "India"; assertEquals(expected, about.getAddress()); } }
and create aboutModel.json file under core/src/test/resource folder
{ "aboutModel": { "email":"abc@gmail.com", "address": "india" } }
Still getting this error
This the test code