> For the complete documentation index, see [llms.txt](https://coldbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox.ortusbooks.com/the-basics/testing-quick-start/interceptor-testing.md).

# Interceptor Testing

Unit test interceptors in isolation with BaseInterceptorTest and pre-mocked controller, logger, and flash dependencies.

You can test interceptors directly with no need of doing integration testing via the `BaseInterceptorTest`. This way you can unit test interceptors in isolation. All you need to do is the following:

```bash
coldbox create interceptor-test path=interceptors.Deploy points=onCreate --open
```

This testing support class will create your interceptor, and decorate with mocking capabilities via MockBox and mock all the necessary companion objects around interceptors. The following are the objects that are placed in the variables scope for you to use:

* `interceptor` : The target interceptor to test
* `mockController` : A mock ColdBox controller in use by the target interceptor
* `mockRequestService` : A mock request service object
* `mockLogger` : A mock logger class in use by the target interceptor
* `mockLogBox` : A mock LogBox class in use by the target interceptor
* `mockFlash` : A mock flash scope in use by the target interceptor

All of the mock objects are essentially the dependencies of interceptor objects. You have complete control over them as they are already mocked for you.

{% tabs %}
{% tab title="BoxLang" %}

```js
/**
* The base interceptor test case will use the 'interceptor' annotation as the instantiation path to the interceptor
* and then create it, prepare it for mocking, and then place it in the variables scope as 'interceptor'. It is your
* responsibility to update the interceptor annotation instantiation path.
*/
class extends="coldbox.system.testing.BaseInterceptorTest" interceptor="interceptors.test"{

    /*********************************** LIFE CYCLE Methods ***********************************/

    function beforeAll(){
        // interceptor configuration properties, if any
        configProperties = {};
        // init and configure interceptor
        super.setup();
        // we are now ready to test this interceptor
    }

    function afterAll(){
    }

    /*********************************** BDD SUITES ***********************************/

    function run(){

        describe( "interceptors.test", () => {

            it( "should configure correctly", () => {
                interceptor.configure();
            });


        });

    }

}
```

{% endtab %}

{% tab title="CFML" %}

```cfscript
/**
* The base interceptor test case will use the 'interceptor' annotation as the instantiation path to the interceptor
* and then create it, prepare it for mocking, and then place it in the variables scope as 'interceptor'. It is your
* responsibility to update the interceptor annotation instantiation path.
*/
component extends="coldbox.system.testing.BaseInterceptorTest" interceptor="interceptors.test"{

    /*********************************** LIFE CYCLE Methods ***********************************/

    function beforeAll(){
        // interceptor configuration properties, if any
        configProperties = {};
        // init and configure interceptor
        super.setup();
        // we are now ready to test this interceptor
    }

    function afterAll(){
    }

    /*********************************** BDD SUITES ***********************************/

    function run(){

        describe( "interceptors.test", function(){

            it( "should configure correctly", function(){
                interceptor.configure();
            });


        });

    }

}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox.ortusbooks.com/the-basics/testing-quick-start/interceptor-testing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
