Contact Us 1-800-596-4880

Writing and Running BAT Tests in IntelliJ IDEA

You can write and run BAT tests in IntelliJ IDEA. The DataWeave 2.0 Intellij plugin, which adds the required support, offers these features:

  • Support for local refactoring

  • Syntax highlighting

  • A view of the structure of the BAT test that you are editing

  • MULE XML language injection

  • String interpolation

  • Support for running tests

About This Task

The steps in this procedure explain how to modify a BAT project for support in IntelliJ IDEA, open that project, create a new test file, and run a test.

Before You Begin

  • Ensure that the DataWeave 2.0 IntelliJ plugin in installed in your IntelliJ IDEA editor. You can install it by following these steps:

    1. In IntelliJ IDEA, open the preferences.

    2. Select Plugins and then click Browse Repositories.

    3. Click Manage Repositories.

    4. Click the plus icon to add a custom repository.

    5. Paste in the following URL: https://plugins.jetbrains.com/plugins/Develop/10362

    6. Click Check Now to verify that the repository is reachable. Then, click OK.

    7. In the Browse Repositories dialog, search on dataweave.

    8. Select DataWeave 2.0 IntelliJ Plugin and then click Install in the plugin details.

    9. Restart IntelliJ IDEA.

  • Log in to BAT in a terminal window and run the bat --update command to be sure that you have the latest version of the BAT CLI.

Write and Run BAT Tests in IntelliJ IDEA

  1. If you do not already have a BAT project that you want to work with, create one with the bat init command in a terminal window.

  2. Inside the project folder, run the command bat idea.

    Result: The command creates a new file in the project: project-name.iml

  3. In IntelliJ IDEA, open the project by selecting the project folder.

  4. In the Project Structure dialog, set the Java SDK that you want to use for your project.

  5. If you want to write a test, create a new test file:

    1. Right-click the folder that contains your tests and select New > DataWeave Component.

    2. In the dialog box, select Bat Test in the Kind field.

    Result: A new Bat Test file appears in the Tests folder. Double-click that to open it in the editor pane. Write your test in that file.

  6. To run a test:

    1. Open the test in the editor.

    2. Right-click in the file and select Run > Bat Test filename.

    Result: The output of the test appears in the Run tool window.