Contact Us 1-800-596-4880

About Before/After Scopes

As with other testing frameworks, MUnit provides certain features around the test suite concept.
In particular, it provides a set of scopes that allow you to add processing or actions to be run before and/or after the entire MUnit Test or MUnit Suite executions:

  • Before and After Suite Scopes.

  • Before and After Test Scopes.

The ID space from each component must be unique across all your application.
This means that before and after scopes cannot share the same name between them, nor have the same name as any flow in your application.

About Before Suite Scope

The MUnit Before Suite contains code that is meant to be executed before the whole suite. The Before Suite has one execution rule: Run before all the tests, just once.

For example, suppose you have an MUnit Test Suite file with four tests. The code inside an MUnit Before Suite runs just once, before your four tests.

You can only use one Before Suite scope per MUnit test suite.
Before Suite example
<munit:before-suite name="before-suite" description="Executes a before suite">
  <!-- some mule code here -->
</munit:before-suite >

<munit:test name="munit.test" description="Test">
  <!-- some more mule code here -->
</munit:test>

Note that the before-suite is located outside the MUnit test.
One instance in which the MUnit Before Suite is useful is when you need to set up a test environment before all tests run.

When you place a before-suite in the Anypoint Studio canvas, the scope locates outside the MUnit test.

About After Suite Scope

The MUnit After Suite is a scope. It can contain code that is meant to be executed after the whole suite.
The After Suite has one execution rule: Run after all the tests, just once.

For instance, let’s suppose you have an MUnit Test Suite File with four tests. The code inside an MUnit After Suite, runs just once, after all your tests.

You can only use one After Suite scope per MUnit test suite.
After Suite example
<munit:before-suite name="before.suite" description="A description">
  <!-- some mule code here -->
</munit:before-suite >

<munit:test name="munit.test" description="Test">
  <!-- some more mule code here -->
</munit:test>

<munit:after-suite  name="after.suite" description="A description">
  <!-- some Mule code here -->
</munit:after-suite >

Note that the after-suite is located outside the MUnit test.
One instance in which the MUnit After Suite is useful is when you need to tear down a test environment after the whole test runs.

When you place an after-suite in the Anypoint Studio canvas, the scope locates outside the MUnit test.

About Before Test Scope

The MUnit Before Test Scope contains code that is meant to be executed before each test.
Each Before Test scope follows the same execution rule: Run before each test.

For instance, let’s suppose you have an MUnit Test Suite file with four tests. The code inside an MUnit Before test runs before each of your four tests; it runs four times.

You can only use one Before Test scope per MUnit test suite.
Before Test example
<munit:before-test name="before.test" description="A description">
  <!-- some mule code here -->
</munit:before-test>

<munit:test name="munit.test" description="Test">
  <!-- some more mule code here -->
</munit:test>

Note that the before.test is located outside the MUnit test.
One instance in which the MUnit Before Suite is useful is when you need to set up a test environment after the whole test runs.

When you place an before-test in the Anypoint Studio canvas, the scope locates outside the MUnit test.

About After Test Scope

The MUnit After Test Scope contains code that is meant to be executed after each test. Each After Test scope follows the same execution rule: Run after each test.

For instance, let’s suppose you have an MUnit Test Suite file with four tests. The code inside an MUnit After Test runs after each of your four tests; it runs four times.

You can only use one After Test scope per MUnit test suite.
After Test example
<munit:before-test name="before.test" description="A description">
  <!-- some mule code here -->
</munit:before-test>

<munit:test name="munit.test" description="Test">
  <!-- some more mule code here -->
</munit:test>

<munit:after-test  name="after.test" description="A description">
  <!-- some mule code here -->
</munit:after-test>

Note that the after.test is located outside the MUnit test.
One instance in which the MUnit After test is useful is when you need to tear down a test environment after the whole test runs.

When you place an after-test in the Anypoint Studio canvas, the scope locates outside the MUnit test.