Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM-junit for text component using textmodel

Avatar

Level 2

I am building  project with Junit for Text

WHEN I return plain text (Lorem ipsum dolor sit amet.) for getText.

THEN I should see “Lorem ipsum dolor sit amet.” returned for getText().

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hey @Babita11 ,

 

Here is a quick reference : unit-testing-aem for Junit testing.

 

For your usecase, you need to mock the model under the test and command the Junits as and when required like:
If someone is calling a getter from mockModel you can use :

when(mockModel.getSomeProperty).thenReturn("Lorem Ipsum...");

 

Here's a tutorial on how you use asserting : junit-assert-tutorial .

 

Please feel free to reach out if that doesnt help. Thanks.

View solution in original post

0 Replies

Avatar

Level 5

Hi @Babita11,

I believe you are looking for Mockito's - when thenReturn function. You will have to use set as below:

when(textModelObject.getText()).thenReturn("Lorem ipsum dolor sit amet.");

with this you will be able to check using assertEquals as below:

assertEquals("Lorem ipsum dolor sit amet.",object.getText());


Hope this helps!
Jineet

Avatar

Correct answer by
Community Advisor

Hey @Babita11 ,

 

Here is a quick reference : unit-testing-aem for Junit testing.

 

For your usecase, you need to mock the model under the test and command the Junits as and when required like:
If someone is calling a getter from mockModel you can use :

when(mockModel.getSomeProperty).thenReturn("Lorem Ipsum...");

 

Here's a tutorial on how you use asserting : junit-assert-tutorial .

 

Please feel free to reach out if that doesnt help. Thanks.