Unit Test for SlingQuery | Community
Skip to main content
Level 3
May 26, 2021 3:41 PM UTC
Solved

Unit Test for SlingQuery

How can I write a unit test to test below Sling Query from my code.

 

List<Resource> legalDisclaimerResourceList = $(legalDisclaimerPageResource).find(LEGAL_DISCLAIMER).asList();

 

$ refers to Sling Query from 

import static org.apache.sling.query.SlingQuery.$;

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
May 27, 2021 2:03 PM UTC

Hi @troubleshooter3,

Per the official Sling docs, Mock implementation for Sling Query is not available in the list of Selected Sling APIs (for which the mock is available)

https://sling.apache.org/documentation/development/sling-mock.html

 

2 replies

New Participant
Jun 22, 2021 11:39 AM UTC

Hey

I am sharing new examples, just look into it , i hope you will find this helpful

For JUnit 5:

<dependency>
  <groupId>org.apache.sling</groupId>
  <artifactId>org.apache.sling.testing.sling-mock.junit5</artifactId>
</dependency>

For JUnit 4:

<dependency>
  <groupId>org.apache.sling</groupId>
  <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
</dependency>

 

Translate
Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
May 27, 2021 2:03 PM UTC

Hi @troubleshooter3,

Per the official Sling docs, Mock implementation for Sling Query is not available in the list of Selected Sling APIs (for which the mock is available)

https://sling.apache.org/documentation/development/sling-mock.html

 

Translate