Skip to content

Debug the test under the cursor

Put the cursor in a test, press one key, land in the debugger. No profile per test, no filter to type.

From the editor

:DebugTest

by default <leader>dT.

From a terminal

bugsaur gui --project . --test-at src/lib.rs:42
bugsaur run --project . --test-at tests/test_orders.py:24

--test-at <file:line> replaces the profile's program with the selected test.

What it does

The profile is still used — the test flow inherits the adapter, environment, working directory and other launch settings from it. Only the program, its arguments and the build are replaced with what the selected test needs.

Language How it builds and runs
Rust cargo test --no-run --message-format=json, then the resulting test binary
Go a test launch through dlv for the selected package or file
Python the selected pytest node through debugpy
PHP PHPUnit through testCommand; see below

Rules to know

The cursor must be inside a test function

The cursor may be on the method declaration or anywhere in its body; Bugsaur selects the containing test method.

On any other line the command refuses and starts nothing. In Rust the
`#[test]` attribute line also counts.

On a **test group** line — `mod tests`, or a PHP class containing recognised
test methods — the same command runs the whole group. Ordinary PHP classes
are not test groups and have no runnable sign in the gutter.

The buffer must be saved

The backend reads the file from disk. Unsaved text cannot be matched reliably against a compiled binary.

Saved breakpoints are not picked up

Unlike :DebugStart, a test run uses only the breakpoints of that request. Set the breakpoint you care about in the same session.

The flags are mutually exclusive

--test-at cannot be combined with --program: one says debug this test, the other debug this program.

It works with run and gui, but not with serve.

PHP needs one extra line

PHP is not launched by Bugsaur, so the profile has to say how to run PHPUnit where PHP lives:

[profiles.docker.launch_arguments]
sessionMode = "server"
port = 9003
pathMappings = { "/app" = "${root}" }
testCommand = ["docker", "compose", "exec", "-T", "-e", "XDEBUG_TRIGGER=1", "php", "php", "vendor/bin/phpunit"]

:DebugTest recognises test* methods and methods with the #[Test] attribute in .php files. For a method it passes --filter Class::method; on the declaration of a class containing such methods it runs the whole file.

testCommand runs after the adapter has started listening, so the listener is already up when Xdebug connects back.

When it does not work

Symptom Fix
The command refuses the cursor is not inside a test function
"buffer not saved" save the file
My breakpoints are ignored expected — set them in this session
Runs the whole suite the cursor was on a group line, not inside a test
PHP does nothing the profile has no testCommand