---
schema_version: "1"
id: 545b43432b43ebe615f7d4301fb4f18a1a9c8cd36b57008fac66629de8d38aa6
title: Spy Event Processor
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/3.6/spy-event-processor.md
canonical_url: https://docs.mulesoft.com/munit/3.6/spy-event-processor
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f2324aa45dd6e10bba2742e80763efc113a0eb9299953f023cb564e8cb5f947c
description: MuleSoft Documentation Site
release: "3.6"
latest: false
---
---
product: MUnit
version: 3.6
keywords: munit, testing, unit testing
---

# Spy Event Processor

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

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

The **Spy Processor** enables you to spy on what happens before and after an event processor is
called.  
This enables you to validate, for example that a selected Mule Event reaches a specific event
processor containing a specific payload or variable.

Setting a spy processor tells MUnit to run a set of instructions (usually assertions or
verifications) before and/or after the execution of the spied event processor.

Assume that you have this configuration:

```xml
<flow name="testFlow">
  <http:request path="/my/api" />
</flow>
```

You can configure the spy processor to spy on any Http Request and assert that the payload is null
before reaching the component, and not null after it’s been processed:

```xml
<munit:test name="suiteTest" >

  <munit:behavior >

    <munit-tools:spy processor="http:request">
      <munit-tools:before-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::nullValue()]"/>
      </munit-tools:before-call>
      <munit-tools:after-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::notNullValue()]"/>
      </munit-tools:after-call>
    </munit-tools:spy>

  </munit:behavior>

</munit:test>
```

Or even to spy on any Http Request, whose path is '/my/api'.

```xml
<munit:test name="suiteTest" >

  <munit:enable-flow-sources >
    <munit:enable-flow-source value="testFlow" />
  </munit:enable-flow-sources>

  <munit:behavior >

    <munit-tools:spy processor="http:request">
      <munit-tools:with-attributes >
        <munit-tools:with-attribute attributeName="path" whereValue="#['/my/api']" />
      </munit-tools:with-attributes>

      <munit-tools:before-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::nullValue()]"/>
      </munit-tools:before-call>

      <munit-tools:after-call >
        <munit-tools:assert-that expression="#[payload]" is="#[MunitTools::notNullValue()]"/>
      </munit-tools:after-call>

    </munit-tools:spy>

  </munit:behavior>

</munit:test>
```

As shown above, this processor enables you to define actions for before and after calling the spied
processor. However, keep in mind that the spy processor does not modify the original Mule Event.  
If you set variables, attributes, or modify the payload inside a Spy, these changes won’t persist
outside the processor.  
Overall, you should use the Spy processor to verify or assert.

## See Also

- [MUnit Event Processors](https://docs.mulesoft.com/munit/3.6/event-processors)
