Most people agree that having a solid unit testing framework is a prerequisite to a viable tech stack. MuleSoft’s application testing framework, MUnit, allows developers to build automated tests for Mule integrations within the Mule XML ecosystem. If additional flexibility is needed, MuleSoft offers a large Java test ecosystem with several base classes that could be used to build powerful tests in Mule 3. Unfortunately, MuleSoft did not continue the testing ecosystem in Mule 4 so AVIO built a Mule Groovy testing framework. The tool is for developers and written by developers. It aims to improve the testing experience for the technical user more than the non-technical user.
What is it?
At its simplest, it’s lines of code that start your Mule app for you (from Maven libraries), aids in mocking, and allows invoking flows using Groovy with xUnit frameworks (e.g. JUnit).
- Favor real languages over graphical configuration files
- Broad test tool ecosystem
- No “lazy loading”, run in the JVM
- Minimize duplication from implementation
What Value Does It Add in These Areas?
There are not many choices in the Mule 4 ecosystem that prioritize the design goals listed above. Because of this, AVIO embraced Groovy due to its similarity to Java and progressive features. It’s always a good idea to use a language designed for writing software and not for describing data like XML/JSON.
MUnit attempts to offer an easy loading option to run tests faster but it can be quite brittle and creates a large change between how Mule loads in normal/non-test situations vs. test situations. Here at AVIO we like to complete the app load as soon as possible so we can focus on future features like a background daemon to keep an app “test run ready” to help improve speed.
Finally, the Groovy Framework also uses the ‘target’ value from the implementation rather than forcing your mocks to repeat what your implementation has already specified.
Here’s a Mule XML under test example:
How Do You Get Started?
Currently, the framework is only available as a source and can be installed using the steps below.
- Clone avioconsulting/mule-4-engine-dependency-resolver and install
- Clone avioconsulting/mule-groovy-testing and install
- Put the proper dependencies and plugins into your Mule app under test’s pom.xml
- Start writing tests - See the README in the mule-groovy-testing repo for more information
The framework is open-source and pull requests/feedback are always welcome.