top of page
Search
  • Writer's pictureJuan Ayala

Speed Up Your AEM Unit Tests

Back in December of 2022, I was working on an AEM 6.5 project. It was a typical project. Including the build time.


Locally, I mitigated the long build by building only what was necessary. i.e. the core bundle. Or skipping the unit tests. Or using the repo tool to sync the only the changes needed. It was only on the CI/CD pipeline that I would have to wait upwards of an hour for it to complete.


Then one day, an off-shore developer submitted a PR. Claiming to have improved the build time. "Popycock!" I said. Well it turns out he was right. And I was completely surprised by the issue. How could this have going on for such a long time?


I mentally filed away this information. I was busy, and forgot about it. It wasn't until 7 months later a co-worker sends me a message. "There's one thing bothering me, the build time caused by the tests. Do you have any suggestions?"


"Yeah! Delete that leaky slf4j test logger!". I responded. Sure enough, the build time went down from 1.5 hours to 20 minutes.


The Culprit: SLF4J Test


WCM Core Components, Issue #1544. Back in May of 2021, someone reported the core bundle unit tests taking a long time. The culprit was the lidalia's slf4j-test SLF4J binding. Guess what. The AEM project archetype also adds this dependency. Check out the core/pom.xml file. This is likely happening in your own project.


Fix It!


Read issue #1544. Then go through the commits on PR #1552. At first, they created a cleanup extension. And they talked about alternatives like spf4j-slf4j-test. Finally, they decided to get rid of that dependency all together. And get rid of any unit test code that was checking the log messages. Instead they chose to verify behavior using Mockito.


Conclusion

My recommendation: get rid of it. Its mere presence in the calsspath means SLF4J will use this binding. Even if you don't write any unit tests that check the log messages.


Personally I have never found a good reason to be testing that things get logged. Instead I focus on testing the code does what it should. And handles exceptions correctly. If you feel like you need to verify your logging, then switch to one of the other alternatives.

If you found removing this SLF4J binding improved your build time, drop me a line.

300 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page