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

Unit Test for SlingQuery

  • May 26, 2021
  • 2 replies
  • 1088 views

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.
Best answer by Vijayalakshmi_S

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

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
Level 10
May 27, 2021

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

 

June 22, 2021

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>