Behave Test Explorer
A Visual Studio Code extension that integrates Behave BDD tests with the Test Explorer, allowing you to run and debug scenarios directly from the IDE.
Features
- Test Explorer Integration: View all your
.feature files and scenarios in VS Code's Test Explorer
- Run Individual Scenarios: Click to run a single scenario or all scenarios in a feature
- Debug Support: Debug tests with breakpoints using debugpy
- Custom Arguments: Configure custom arguments for your test runner
- Argument Presets: Save and switch between different argument configurations
- Tag-based Running: Run scenarios by selecting tags
- CodeLens: Run/Debug buttons directly in your feature files
- Document Symbols: Navigate scenarios using the Outline view
Installation
From Source
- Clone this repository
- Run
npm install to install dependencies
- Run
npm run compile to compile TypeScript
- Press F5 to run the extension in a new VS Code window
Building VSIX
npm install
npm run compile
npm run package
Configuration
Configure the extension in your VS Code settings or workspace settings:
{
"behaveTestExplorer.runnerScript": "runner.py",
"behaveTestExplorer.pythonPath": "python",
"behaveTestExplorer.featuresPath": "features",
"behaveTestExplorer.excludeTag": "@ignore",
"behaveTestExplorer.defaultArgs": [],
"behaveTestExplorer.customArgs": {
"Smoke Tests": [
"--tag=@smoke"
],
"Regression": [
"--tag=@regression",
"--exclude_tag=@ignore"
]
}
}
Custom Runner Arguments
If your runner script accepts custom arguments (like --product, --board, etc.), you can configure them:
{
"behaveTestExplorer.defaultArgs": [
"--env=staging",
"--verbose"
],
"behaveTestExplorer.customArgs": {
"Production": ["--env=prod", "--tag=@smoke"],
"Development": ["--env=dev", "--tag=@wip"]
}
}
Settings
| Setting |
Description |
Default |
behaveTestExplorer.runnerScript |
Path to your runner script (relative to workspace) |
runner.py |
behaveTestExplorer.pythonPath |
Path to Python executable |
python |
behaveTestExplorer.featuresPath |
Path to features directory |
features |
behaveTestExplorer.excludeTag |
Tag to exclude (--exclude_tag) |
@ignore |
behaveTestExplorer.defaultArgs |
Array of default arguments to pass to runner |
[] |
behaveTestExplorer.customArgs |
Named argument presets (object with name → args array) |
{} |
Usage
Running Tests
- Open the Test Explorer view (View → Testing or
Ctrl+Shift+T)
- Your feature files and scenarios will appear in the tree
- Click the play button to run:
- A single scenario
- All scenarios in a feature
- All tests in the workspace
Using Custom Arguments
- Click the Behave status bar item (bottom left) to select an argument preset
- Or use command palette:
Behave Test Explorer: Select Argument Preset
- Or right-click a test and select "Run with Custom Arguments"
Running by Tag
- Open command palette (
Ctrl+Shift+P)
- Run
Behave Test Explorer: Run Scenario by Tag
- Select a tag from the list
Configuring Arguments
- Open command palette
- Run
Behave Test Explorer: Configure Arguments
- Select what you want to configure
Creating Presets
Add presets in your settings.json:
{
"behaveTestExplorer.customArgs": {
"My Preset Name": [
"--tag=@myTag",
"--format=pretty"
],
"CI Pipeline": [
"--tag=@smoke",
"--no-capture",
"--format=json"
]
}
}
Commands
| Command |
Description |
Behave Test Explorer: Refresh Tests |
Refresh the test tree |
Behave Test Explorer: Run with Custom Arguments |
Run selected test with custom args |
Behave Test Explorer: Configure Arguments |
Open argument configuration UI |
Behave Test Explorer: Select Argument Preset |
Switch between saved presets |
Behave Test Explorer: Run Scenario by Tag |
Run all scenarios with a specific tag |
Runner Script Compatibility
This extension is designed to work with custom runner scripts (like runner.py) or directly with Behave. Common arguments:
--tag=<value> - Run scenarios with this tag
--exclude_tag=<value> - Exclude scenarios with this tag
--name=<value> - Run scenario by name
--include=<path> - Include specific feature file
- Any custom arguments your runner script accepts
You can configure any arguments your runner needs using defaultArgs or customArgs presets.
--include=<path> - Include specific feature file
If your runner uses different arguments, configure them using defaultArgs or create presets.
Requirements
- VS Code 1.85.0 or higher
- Python 3.x with Behave installed
- A runner script (like
runner.py)
Troubleshooting
Tests not appearing
- Make sure your
.feature files are in the configured featuresPath directory
- Run
Behave Test Explorer: Refresh Tests command
- Check the output channel "Behave Test Runner" for errors
Tests failing to run
- Verify
pythonPath is correct
- Verify
runnerScript path is correct
- Check the output channel for the exact command being run
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.