Hi all,
I am trying to write Junit test by using WCM IO testing tools. I have been reading lots of articles but I can't make it work. The steps I follow are:
<dependency> <groupId>io.wcm</groupId> <artifactId>io.wcm.testing.aem-mock</artifactId> <version>2.2.0</version> </dependency>
Add test case within the core bundle
package com.my.project.core.models; import org.apache.sling.api.resource.ResourceResolver; import org.junit.Rule; import org.junit.Test; import io.wcm.testing.mock.aem.junit.AemContext; public class MyFirstITest { @Rule public final AemContext context = new AemContext(); @Test public void itWorksTest() throws Exception { ResourceResolver rr = context.resourceResolver(); // Test someting } }
Does anybody use this library to write unit tests? Does anybody make it work? I have been following: http://wcm.io/testing/aem-mock/usage.html#Sling_Models
Cheers,
Salva.
Solved! Go to Solution.
Hi, Salvador.
Were you able to make it work?
I'm still testing wcm.io with 6.2 but, for now, the following list of dependencies (pom.xml) has worked for me:
<dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> <scope>test</scope> </dependency> <dependency> <groupId>junit-addons</groupId> <artifactId>junit-addons</artifactId> <version>1.4</version> <scope>test</scope> </dependency> <dependency> <groupId>io.wcm.maven</groupId> <artifactId>io.wcm.maven.aem-dependencies</artifactId> <version>6.2.0.0000</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>io.wcm</groupId> <artifactId>io.wcm.testing.aem-mock</artifactId> <version>2.2.0</version> <!-- http://wcm.io/testing/aem-mock/ --> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-imaging</artifactId> <version>1.0-R1534292</version> <scope>test</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.6.6</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.6.6</version> <scope>test</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>com.adobe.aem</groupId> <artifactId>uber-jar</artifactId> <version>6.2.0</version> <scope>provided</scope> <classifier>apis</classifier> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.6</version> <scope>test</scope> </dependency> <!-- more dependencies here -->
It came from combining AMC AEM Archetype + ACS AEM Lazybones + a fair amount of trial and error.
Regards,
Daniel.
Views
Replies
Total Likes
Even I am facing the same issue.
Views
Replies
Total Likes
Hi, Salvador.
For AEM 6.1, we've been using the following combination of test libraries:
<dependency> <groupId>io.wcm.maven</groupId> <artifactId>io.wcm.maven.aem-dependencies</artifactId> <version>6.1.0.0000</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>io.wcm</groupId> <artifactId>io.wcm.testing.aem-mock</artifactId> <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>junit-addons</groupId> <artifactId>junit-addons</artifactId> <version>1.4</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.5.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.6.4</version> <scope>test</scope> </dependency>
Maybe there is also an io.wcm.maven.aem-dependencies for AEM 6.2...
Regards,
Daniel.
Hi Daniel,
It helps a lot to resolve the previous issue and now, I can use AemContext Object. However, I am facing the next issue:
Running wcm.salvaITest.PageTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.398 sec <<< FAILURE! - in wcm.salvaITest.PageTest
testSomething(wcm.salvaITest.PageTest) Time elapsed: 0.322 sec <<< ERROR!
java.lang.NoClassDefFoundError: org/apache/sling/models/factory/ModelFactory
All I have done so far is:
Have you also faced this issue?
Obrigado, Salva.
Views
Replies
Total Likes
Hi, Salvador.
As a side note:
I think it.tests project is meant for integration tests only: server-side tests that run inside AEM.
I would put unit tests in a different child project/module.
About your question:
It seems that some dependencies are still missing... Does IntelliJ automatically import the dependencies declared in Maven POM files?
Regards,
Daniel.
Views
Replies
Total Likes
Hi, Salvador.
<dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.models.api</artifactId> <version>1.2.2</version> <scope>provided</scope> </dependency>
You can discover which version to use by searching for org.apache.sling.models.factory.ModelFactory at the /system/console/depfinder.
If IntelliJ is not able to automatically import the dependencies declared in your POM files, I would say to you:
Best regards,
Daniel.
Views
Replies
Total Likes
We have added this use case to the list of HELPX articles to write. All of this information should be in an article. We hope to get this written shortly after Digital Marketing summit.
Views
Replies
Total Likes
Hi, Salvador.
Were you able to make it work?
I'm still testing wcm.io with 6.2 but, for now, the following list of dependencies (pom.xml) has worked for me:
<dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> <scope>test</scope> </dependency> <dependency> <groupId>junit-addons</groupId> <artifactId>junit-addons</artifactId> <version>1.4</version> <scope>test</scope> </dependency> <dependency> <groupId>io.wcm.maven</groupId> <artifactId>io.wcm.maven.aem-dependencies</artifactId> <version>6.2.0.0000</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>io.wcm</groupId> <artifactId>io.wcm.testing.aem-mock</artifactId> <version>2.2.0</version> <!-- http://wcm.io/testing/aem-mock/ --> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-imaging</artifactId> <version>1.0-R1534292</version> <scope>test</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.6.6</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.6.6</version> <scope>test</scope> </dependency> <!-- more dependencies here --> <dependency> <groupId>com.adobe.aem</groupId> <artifactId>uber-jar</artifactId> <version>6.2.0</version> <scope>provided</scope> <classifier>apis</classifier> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.6</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.6</version> <scope>test</scope> </dependency> <!-- more dependencies here -->
It came from combining AMC AEM Archetype + ACS AEM Lazybones + a fair amount of trial and error.
Regards,
Daniel.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies