---
schema_version: "1"
id: af12bdde86407fb050e101238a0bed5cb45b67bd5a49d904730c980312086858
title: Testing DataWeave Libraries and Modules
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dataweave-testing-framework.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dataweave-testing-framework
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6d7a2ec31aeca2f531b12555e82bd52b357d8dc63fadd3b3ba5db2da06769b04
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# Testing DataWeave Libraries and Modules

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The DataWeave testing framework enables you to build automated unit and integration tests for your
DataWeave libraries and mappings. You can run tests to evaluate `.dwl` files and compare them to the
output produced by the system you’re testing. The framework provides a full suite of integration and
unit test capabilities with a built-in set of assertion functions, and it is completely integrated
with Maven and Surefire for your continuous deployment environment.

Use snapshot testing for your integration tests by storing the expected outputs as a separate file
rather than as a string literal inside the test code.

You can create tests for your DataWeave mappings and modules either by using the Visual Studio Code
(VS Code) plugin, see [Installing and Using the DataWeave Extension](https://docs.mulesoft.com/dataweave/2.6/dataweave-extension-plugin) for
instructions, or manually by modifying your project’s `pom.xml` file.

## Add the DataWeave Testing Framework to Your Project

To enable the DataWeave Testing Framework in your project:

- Add the following Maven dependency to your project’s `pom.xml` file:

  ```xml
   <dependency>
     <groupId>org.mule.weave</groupId>
     <artifactId>data-weave-testing-framework</artifactId>
     <version>${data.weave.testing.framework.version}</version>
     <scope>test</scope>
   </dependency>
  ```

## Tests Structure

The following table shows the different files that compose a test, a description of their
functionalities, and their default locations:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>File</th><th>Description</th><th>Location</th></tr></thead><tbody><tr><td><div><div><p>DataWeave Mapping</p></div></div></td><td><div><div><p>The <code>.dwl</code> file that contains the mapping to test.</p></div></div></td><td><div><div><p><code>src/main/dw/&lt;package&gt;/&lt;mappingFileName&gt;</code></p></div></div></td></tr><tr><td><div><div><p>DataWeave Test</p></div></div></td><td><div><div><p>The <code>.dwl</code> file that contains the tests and assertions to execute.</p></div></div></td><td><div><div><p><code>src/test/dw/&lt;package&gt;/&lt;testFileName&gt;</code></p></div></div></td></tr><tr><td><div><div><p>Input</p></div></div></td><td><div><div><p>The file that contains the input to evaluate against the mapping. Depending on the test, this file is optional.</p></div></div></td><td><div><div><p><code>src/test/resources/&lt;mappingPath&gt;/&lt;scenario&gt;/inputs/&lt;inputFile&gt;</code></p></div></div></td></tr><tr><td><div><div><p>Output</p></div></div></td><td><div><div><p>The file that contains the output to check against the results of the mapping.</p></div></div></td><td><div><div><p><code>src/test/resources/&lt;mappingPath&gt;/&lt;scenario&gt;/&lt;outputFile&gt;</code></p></div></div></td></tr></tbody></table>

## Create an Integration Test for a Mapping

To test a DataWeave mapping, create an integration test by following these steps:

1.  Create a `.dwl` file with a name ending in `Test` in the `src/test/dw/<package>/<testFileName>`
    folder.

2.  In the test file’s header, import the `dw::test::Tests` and `dw::test::Asserts` modules.

3.  In the test file’s body, nest any number of sections (`“sectionName”`), followed by
    `describedBy`, and specify the test name at the end (`“testName”`), followed by
    `in do {<codeExecution/assertion>}`.

4.  In the code execution and assertion part of the test file, specify the following:

    - The `inputsFrom(<inputPath>)` function, to get the inputs to evaluate against the mapping

    - The `evalPath(<mapping/scenario>)` function, to specify the mapping path

    - The `must equalTo` matcher to check the results against the expected output specified by
      function `outputFrom(<mapping/scenario>)`

5.  Add the expected inputs and outputs to the `src/test/resources/<mappingPath>` folder.

6.  If you want to configure the reader properties for the inputs, create a properties file with
    suffix `{fileName}-config.properties` in the `src/test/resources/<mappingPath>/inputs/` folder.

### Example Mapping Test

The following example shows a DataWeave test that contains a DataWeave mapping file, an input file,
a reader properties configuration file, an output file, and a test file, respectively:

- DataWeave mapping in `src/main/dw/myPackage/MyMapping.dwl`

  ```dataweave
  %dw 2.0
  output application/json
  ---
  {
    hello: "world"
  }
  ```

- Input file in `src/test/resources/myPackage/MyMapping/NewScenario/inputs/payload.json`

  ```dataweave
  {
    "message": "Hello world!"
  }
  ```

- Reader properties configuration file in
  `src/test/resources/myPackage/MyMapping/NewScenario/inputs/payload-config.properties`

  ```dataweave
  streaming=false
  ```

- Expected output file in `src/test/resources/myPackage/MyMapping/NewScenario/out.json`

  ```dataweave
  {
    "hello": "world"
  }
  ```

- Test file in `src/test/dw/myPackage/MyMappingTest.dwl`

  ```dataweave
  %dw 2.0
  import * from dw::test::Tests
  import * from dw::test::Asserts
  ---
  "Test MyMapping" describedBy [
     "Assert NewScenario" in do {
         evalPath("myPackage/MyMapping.dwl", inputsFrom("myPackage/MyMapping/NewScenario"),"application/json") must
                   equalTo(outputFrom("myPackage/MyMapping/NewScenario"))
     }
  ]
  ```

## Create a Unit Test for a Module

To create a unit test for a module:

1.  Create a `.dwl` file with a name ending in `Test` in the `src/test/dw/<package>/<testFileName>`
    folder.

2.  In the test file’s header, import `dw::test::Tests`, `dw::test::Asserts`, and the custom module
    you want to test, for example, `"MyModule"`.

3.  In the test file’s body, nest any number of sections (`“sectionName”`) followed by
    `describedBy`, and specify the test name at the end (`“testName”`).

4.  In the code execution and assertion part of the test, call the function you want to test
    (`functionToTest()`) and add an assertion against its result, for example, `must beObject()`.

### Example Unit Test for a Module

Example `src/test/dw/MyModuleTest.dwl` file:

```dataweave
%dw 2.0
import * from dw::test::Tests
import * from dw::test::Asserts

import * from MyModule
---
"MyModule" describedBy [
   "something" describedBy [
       "It should do something" in do {
           something() must beObject()
       },
   ],
]
```

## Create an Integration Test for a Module

To create an integration test for a module:

1.  In your test folder, create a DataWeave mapping that uses the module you want to test.

2.  Follow the steps in [Creating an Integration Test for a Mapping](#create-test).

## Run the Tests from the Command Line

You can run the tests from the command line by running the `mvn test` command:

- To run a single test, use `mvn -Dtest=<MyMappingTest> test`.

- To skip a test, use `mvn install -DskipTests`.

## Matchers

The testing framework includes a set of matchers to use in your tests. See the
[DataWeave assertions module](https://docs.mulesoft.com/dataweave/2.6/dw-test-asserts) for reference information.

## See Also

- [DataWeave Extension](https://docs.mulesoft.com/dataweave/2.6/dataweave-extension)

- [Packaging and Deploying DataWeave Libraries](https://docs.mulesoft.com/dataweave/2.6/dataweave-maven-plugin)

- [Installing and Using the DataWeave Extension](https://docs.mulesoft.com/dataweave/2.6/dataweave-extension-plugin)
