What are the best ways to unit test java classes? | Community
Skip to main content
Level 3
Aug 2, 2017 5:39 AM UTC
Solved

What are the best ways to unit test java classes?

Hi,

I've gone through Sling and AEM Mocks but none of those seem helpful to test our custom java classes which has services defined by us along with resource, jcr nodes, session etc. Sling and AEM mock only test Sling and JCR apis. Is there any way to test normal java classes as well along with it? Normal Junit with mockito and powermockito requires a lot more effort and we don't want to do that.

Any good examples would be helpful.

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Singaiah_Chintalapudi
Singaiah_ChintalapudiAccepted solution
Level 7
Aug 3, 2017 5:25 PM UTC

7 replies

smacdonald2008
Level 10
Aug 3, 2017 5:34 PM UTC

Great community content that you referenced here.

Translate
Singaiah_Chintalapudi
Singaiah_ChintalapudiAccepted solution
Level 7
Aug 3, 2017 5:25 PM UTC
vitis90Author
Level 3
Aug 3, 2017 6:35 AM UTC

Thank you for replying.

I’ve already gone through this document

https://docs.adobe.com/content/ddc/en/gems/From-Unit-Testing-to-Integration-Test-of-an-AEM-Application/_jcr_content/par/download/file.res/AEM%20GEMS%20-%20Testing%2012-14-2016.pdf

But AEM Mocks and AEM Context seem more likely to test content, register OSGI services and AEM components only.

My question was - if we have normal java objects (which belong to different APIs) as well along with Sling and JCR APIs in a Java class do we have to use Mockito along with it, like we do it for normal junits or AEM Mocks would be sufficient?

If we can get some examples it’d be great.

Translate
kautuk_sahni
Employee
Aug 3, 2017 4:55 AM UTC
smacdonald2008
Level 10
Aug 2, 2017 3:03 PM UTC

See this GEMS webinar - it shows best practice with respect to JUNIT testing with AEM -- From Unit Testing to Integration Test of an AEM Application

Translate
vitis90Author
Level 3
Aug 2, 2017 12:01 PM UTC

do you have any examples for it? Ever tried AEMMock?

Translate
viveksachdeva
New Participant
Aug 2, 2017 7:05 AM UTC

Try Spock.. It is really expressive and eases writing Test cases..

Spock

Translate