---
schema_version: "1"
id: b931475cbdd1143e5b4fb6ff86c5788d4c76adb96bfb9db62b5f35cef334160f
title: Before and After Scopes
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/2.3/before-after-scopes-reference.md
canonical_url: https://docs.mulesoft.com/munit/2.3/before-after-scopes-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 84e2d42130445ab2425d2e312b88b1e3207bfd0bd43eb262a504f3ab9b7e9bfd
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: MUnit
version: 2.3
---

# Before and After Scopes

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

## 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.

> [!NOTE] You can only use one Before Suite scope per MUnit test suite.

Before Suite example

```xml
<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.

## 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.

> [!NOTE] You can only use one After Suite scope per MUnit test suite.

After Suite example

```xml
<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.

## 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.

> [!NOTE] You can only use one Before Test scope per MUnit test suite.

Before Test example

```xml
<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 Test is useful is when you need to set up a test environment before each test run, like
creating a file or setting a variable that will be consumed in each test.

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

## 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.

> [!NOTE] You can only use one After Test scope per MUnit test suite.

After Test example

```xml
<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.

## Before Suite Reference

<table><colgroup><col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Defines the name of the Before suite. The name must be unique inside the suite.</p></td></tr><tr><td><p><code>description</code></p></td><td><p>Describes the actions performed.</p></td></tr></tbody></table>

## After Suite Reference

<table><colgroup><col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Defines the name of the After suite. The name must be unique inside the suite.</p></td></tr><tr><td><p><code>description</code></p></td><td><p>Describes the actions performed.</p></td></tr></tbody></table>

## Before Test Reference

<table><colgroup><col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Defines the name of the Before test. The name must be unique inside the suite.</p></td></tr><tr><td><p><code>description</code></p></td><td><p>Describes the actions performed.</p></td></tr></tbody></table>

## After Test Reference

<table><colgroup><col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>name</code></p></td><td><p>Defines the name of the After test. The name must be unique inside the suite.</p></td></tr><tr><td><p><code>description</code></p></td><td><p>Describes the actions performed.</p></td></tr></tbody></table>
