|
| 1 | +# Debugging Groovy scripts |
| 2 | + |
| 3 | +You can attach a debugger to the JVM to step through your Groovy scripts, inspect variables etc. |
| 4 | + |
| 5 | +The key steps involved are: |
| 6 | + |
| 7 | +1. Enable the JVM debugger, listening on a local port |
| 8 | +2. Start Imposter |
| 9 | +3. Connect to the debug port |
| 10 | + |
| 11 | +## Enable the JVM debugger |
| 12 | + |
| 13 | +Enable the JVM debugger with the following environment variable: |
| 14 | + |
| 15 | + JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000" |
| 16 | + |
| 17 | +> **Note** |
| 18 | +> Here we have set the debug port to 8000. |
| 19 | +
|
| 20 | +### Docker users |
| 21 | + |
| 22 | +When running in Docker, make sure to expose the debug port. |
| 23 | + |
| 24 | +For example: |
| 25 | + |
| 26 | +```bash |
| 27 | +docker run --rm -it -p8080:8080 -p8000:8000 -v $PWD:/opt/imposter/config outofcoffee/imposter |
| 28 | +``` |
| 29 | + |
| 30 | +> In this example, port 8000 is exposed along with the regular port, 8080. |
| 31 | +
|
| 32 | +## Steps for IntelliJ IDEA |
| 33 | + |
| 34 | +These steps will explain how to connect your IDE's debugger to the debug port. |
| 35 | + |
| 36 | +In IntelliJ, create a simple project pointing to the directory containing your script file. |
| 37 | + |
| 38 | +In the following steps, we will add a new run configuration, start your mock and attach the debugger. |
| 39 | + |
| 40 | +### Step-by-step |
| 41 | + |
| 42 | +1. Add a 'Remote JVM Debug' run configuration: |
| 43 | +  |
| 44 | +2. Set the `Port` to the same value as the debug configuration. |
| 45 | +3. Start Imposter and wait for the server to be ready. |
| 46 | +4. In IntelliJ start the run configuration in Debug mode, which will connect the debugger to the Imposter JVM. |
| 47 | + |
| 48 | +Set breakpoints in the script file as normal. When your script is invoked in Imposter, the debugger will pause on breakpoints and you can evaluate variables in scope. |
| 49 | + |
| 50 | + |
0 commit comments