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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Unit Test for SlingQuery

troubleshooter3
Level 2
Level 2

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.$;

 

1 Accepted Solution
Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

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

 

View solution in original post

2 Replies
Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

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

 

View solution in original post

snehalharshe
Level 1
Level 1

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>