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().
Solved! Go to Solution.
Views
Replies
Total Likes
Hey @vinuu123 ,
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.
Hi @vinuu123,
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
what is object here(object.getText()) and what is textmodelobject
Hey @vinuu123 ,
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.
Hi,
Check sample test cases with example at https://github.com/arunpatidar02/com.aemlab.junitapp/tree/master/core/src/test
Views
Likes
Replies