Search code examples
unit-testingassertdataweavemule-esb

How do you unit test dataweave code using Mulesoft's Dataweave Assersion Library?


I want to unit test Dataweave code without using the MUnit message processors in Anypoint Studio. I am following this documentation https://docs.mulesoft.com/munit/2.2/dataweave-assertions-library.

I've attempted to get the following code to run in a transform processor in a regular flow, as well as in a transform that was inside of an MUnit test flow, neither worked.

%dw 2.0
output application/java
import * from dw::test::Asserts
---
[1, 4, 7] must beArray()

When ran in a regular flow I get the following error: Reason: Unable to resolve module with identifier dw::test::Asserts..

When ran in an MUnit test flow, the test always passes even if you have a non array in place of [1, 4, 7] causing a logical error.


Solution

  • The intended use of the DataWeave Assertions library is in the processor as documented at https://docs.mulesoft.com/munit/2.2/assertion-expression-processor. Using them in a regular Transform processor should not be expected to work.