Expand my Community achievements bar.

SOLVED

Junit is not working for multifield on the AEM project created using the lazybone template.

Avatar

Level 2

Issue :

We tried creating the jUnit using jupiter API for one of our nested multifield model, but currently it is not able to fetch the multifield and nested multifield values hence we are getting a NPE.

Surprisingly, it works when we remove the tag <packaging>bundle<packaging> from the core pom file.

 

Analysis : 

When we remove <packaging>bundle<packaging>, the default value of <packaging> tag which is 'jar' will be considered and hence our testcases are running smoothly. but we cannot remove <packaging>bundle<packaging> this from the core pom. 

 

Any thoughts / inputs would definitely help us.

 

Info:

  • My project is created using lazybone template
  • Currently it is on 6.5.13.
  • We had to incorporate all the necessary junit plugins manually as the lazybone template doesn't have them.

suprithanbhat_0-1712073925887.png

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Thanks for your inputs @EstebanBustamante.

 

I tried incorporating Junit4, it is working as expected.

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

 

The archetype by default includes the junit-jupiter dependencies (https://github.com/adobe/aem-project-archetype/blob/758aa13f33d4dabf5d01d0605491b2b6ae728553/src/mai...), so you should be able to use it without any problems. Ideally, if you are testing multifield or nested multifield values, you should mock those values. If the framework is unable to fetch them, there may be an issue with how you are initializing or loading the resources for the test. Could you please post the error you are encountering? Additionally, you can check here for information on how to test a multifield: https://medium.com/@veena.vikraman19/aem-junit-for-simple-aem-component-with-multifield-2326f61c8982

 

Hope this helps.



Esteban Bustamante

Avatar

Level 2

@EstebanBustamante  Thanks for the response. As I mentioned in my original post, the project is not created using the archetype, it is created using the lazybone template https://github.com/Adobe-Consulting-Services/lazybones-aem-templates/tree/master/templates/aem-multi... which doesn't have any jUnit related configurations by default.

 

Let me know if you have any thoughts. 

Avatar

Community Advisor

Sorry about that, I didn't read it carefully.

 

Which version of the junit-jupiter dependency are you using? My thought is that the version of Junit you are trying to run does not function properly due to a missing phase in the bundle packaging type. Are you using the Maven Bundle Plugin? can you try running an older version of Junit?

 



Esteban Bustamante

Avatar

Level 2

Hi @EstebanBustamante 

 

Below are the junit related dependencies which I'm using.

 

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.1.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.1.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>4.1.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.caconfig-mock-plugin</artifactId>
<version>1.3.6</version>
</dependency>


<dependency>
<groupId>com.adobe.cq</groupId>
<artifactId>core.wcm.components.testing.aem-mock-plugin</artifactId>
<version>${core.wcm.components.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>uk.org.lidalia</groupId>
<artifactId>slf4j-test</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>

 

Also, Yes I'm using Maven Bundle Plugin too.

 

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<version>3.3.0</version>

</plugin>

 

and in my core pom, I have included it in the below manner under <build>

 

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<extensions>true</extensions>

<configuration>

<instructions>

<Bundle-SymbolicName>com.xyz.xyz-project</Bundle-SymbolicName>

<Sling-Model-Packages>com.xyz.core.models, com.xyz.core.v3.models</Sling-Model-Packages>

</instructions>

</configuration>

</plugin>

Avatar

Correct answer by
Level 2

Thanks for your inputs @EstebanBustamante.

 

I tried incorporating Junit4, it is working as expected.