Expand my Community achievements bar.

SOLVED

HTL Sightly Unit tests

Avatar

Level 4

HTL Sightly templates are a blind spot in our code base. 

 

We can unit test the Java Classes, the TypeScript scripts or e.g. React.js components, but not the HTL Sightly templates.

 

Does anyone know of a way to (unit) test those?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @jeremylanssiers 
HTL is going to render the HTML, you can test UI.

 

There used to be a framework which is depricated now to test AEM components

https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/compon...



Arun Patidar

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @jeremylanssiers 

Unit testing HTL (Sightly) templates can be challenging because they are primarily designed for rendering HTML and are tightly coupled with the AEM platform. However, there are a few approaches you can consider to test HTL templates to some extent:

1. Integration Testing: Instead of unit testing individual HTL templates, you can perform integration testing by rendering the entire page or component that includes the HTL template. This can be done using tools like AEM Mocks or AEM Mocks JUnit. These tools provide a simulated AEM environment for testing and allow you to render and test the HTL templates in the context of a complete AEM component.

2. Component Testing: AEM 6.5 introduced a new feature called "Component Testing" that allows you to write tests for AEM components, including HTL templates. Component Testing uses a combination of JUnit and the AEM Mocks framework to simulate the AEM environment and test the behavior of components. With Component Testing, you can write tests that cover the rendering and logic of HTL templates.

3. Static Analysis: Another approach is to use static analysis tools to analyze the HTL templates for potential issues or errors. Tools like SonarQube or the AEM Rules for SonarQube plugin can analyze the HTL code and provide feedback on code quality, security vulnerabilities, and potential bugs. While this approach doesn't directly test the functionality of the HTL templates, it can help identify potential issues and improve code quality.

Using integration testing, component testing, and static analysis, you can still cover a significant portion of the functionality and ensure the quality of your HTL templates.

Thanks.



Avatar

Correct answer by
Community Advisor

Hi @jeremylanssiers 
HTL is going to render the HTML, you can test UI.

 

There used to be a framework which is depricated now to test AEM components

https://experienceleague.adobe.com/docs/experience-manager-65/content/implementing/developing/compon...



Arun Patidar

Avatar

Administrator

@jeremylanssiers Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni