Search This Blog

Saturday 28 January 2017

Unit testing AEM - Junit Basic

Junit Basic annotation


  1. @Before – Run before every @Test, public void
  2. @After – Run after every @Test, public void
  3. @Test – This is the test method to run, public void

  • Maven Setup
  • ·     All tests go at src/test/java
  • ·       Include junit as test dependency
  • Create test class, annotate method with org.junit.Test annotation
  • Assertions from org.junit.Assert.*
  • Use Before/ After annotation for setup/clean up



Junit Dependency / Pom.xml

<!-- Testing -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.5.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.9.5</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit-addons</groupId>
                <artifactId>junit-addons</artifactId>
                <version>1.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                        <groupId>commons-io</groupId>
                        <artifactId>commons-io</artifactId>
                        <version>2.4</version>
                        <scope>provided</scope>
                  </dependency>
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>2.9.1</version>

            </dependency>

No comments:

Post a Comment