- If not already running, run your AMP project in IntelliJ as detailed in the previous tutorial. Make sure that Alfresco has fully started.
- In the IntelliJ Project Explorer expand src/test/java to locate the DemoComponentTest.java source file.
- Load it into the editor by double-clicking it.
- Now set up a Run Configuration to run JUnit tests. From the main menu select .
- In the Run/Debug Configurations dialog, click '+' to create a new configuration. Select JUnit from the list of available configuration types.
- Set the Name field of the configuration to "DemoComponentTest".
- In the Class field, select the class (if not already present).
Set the VM options field as follows:
-ea -Xms1024m -Xmx4096m -XX:PermSize=1024m -javaagent:/Users/tbedford/Downloads/springloaded-1.2.0.RELEASE.jar -noverifyAttention: Change the path to Spring Loaded to reflect your system.
- Set the project Working directory to the root of the project (if not already present).
- Click OK.
Now run the test by selecting
from the main menu.
The test will run, and three tests will pass.
- Now, in DemoComponentTest.java, modify one of the tests so that it will fail. For example, you could change the line assertEquals(7, childNodeCount); to assertEquals(8, childNodeCount);
Now run the test again by right-clicking the file in Project Explorer and
selecting Run 'DemoComponentTest' .
Note the test will run again and this time fail. But you did not need to restart Alfresco. This demonstrates hot reloading of Java code.
Change the code back and re-run the test.
It will immediately show green, with all tests passing. The code has re-run without any reloading of Alfresco! This allows for Test Driven Development with very low overhead.