TestNG Runner VS Code Extension
Run TestNG suites directly from VS Code with a dedicated sidebar.
Project Source Code:
GitHub Link
Interactive AI Documentation
NotebookLM link
Features
- Scan workspace for XML whose root element is
<suite>, with or without the TestNG DOCTYPE declaration.
- Run or stop suites from the sidebar.
- Run or debug a suite from an XML editor's right-click menu.
- Debug suites with breakpoints from the sidebar.
- Stream Maven output to a dedicated Output channel.
- Run all suites.
- Persist last run status (time and exit code).
- Per-suite log files.
How To Use In VS Code
1) Install the extension
Install TestNG Runner from the Visual Studio Code Marketplace:
- In VS Code, open
Extensions
- Search for
TestNG Runner
- Select the extension published by Kumar Priyank
- Click
Install
Marketplace page:
2) Open your Java/TestNG project
Open the project that contains:
- a
pom.xml
- one or more TestNG suite XML files
The extension recognizes a suite by its root <suite> element. The TestNG DOCTYPE declaration is optional; when present, it can look like this:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
3) Open the TestNG Runner view
In the Activity Bar, click TestNG Runner.
The sidebar shows TestNG suite files grouped by workspace folder and directory. If a suite has been run before, its last run time and exit code appear next to it.
If mvn and java are already available on your system PATH, you can skip this step.
Otherwise open VS Code settings and search for TestNG Runner, then set:
testngRunner.mavenHome
testngRunner.javaHome
Examples:
C:\Program Files\Apache\maven
C:\Program Files\Java\jdk-17
The status bar shows whether Maven and Java are currently resolved.
5) Run a suite
Use any of these entry points from the TestNG Runner view:
- Click the inline Run TestNG Suite icon next to a suite
- Right-click a suite and choose Run TestNG Suite
- Click Run All TestNG Suites in the view title to run every discovered suite
- Open a suite XML file, right-click in the editor, and choose Run TestNG Suite or Debug TestNG Suite
The extension finds the nearest pom.xml above the selected suite and runs Maven from that directory.
5b) Run every suite inside a folder
Folders and subfolders that contain detected TestNG suite XML files also support inline actions.
You can hover a folder in the TestNG Runner view and:
- click Run TestNG Suite to run every suite under that folder recursively
- click Debug TestNG Suite to debug every suite under that folder sequentially
- click Stop TestNG Suite to stop every running suite under that folder
- click Open TestNG Suite Log to choose and open one suite log from that folder
This makes it easier to run a logical group of suites without triggering the entire workspace.
6) Watch logs and output
Runtime output is written to:
- the shared TestNG Runner Output channel
- a suite-specific output channel
- a per-suite log file
To open the log file for a suite:
- Right-click the suite
- Select Open TestNG Suite Log
7) Stop a running suite
Click the inline Stop TestNG Suite icon for the running suite, or use the suite context menu.
If you stop from a folder, the extension stops all running suites inside that folder tree.
8) Debug a suite with breakpoints
To debug instead of run:
- Click the inline Debug TestNG Suite icon
- Or right-click a suite and choose Debug TestNG Suite
The extension starts Surefire with JDWP enabled and tries to auto-attach the VS Code Java debugger on testngRunner.debugPort (default 5005).
If you start debug from a folder, the extension debugs each suite in that folder one by one.
Use Stop TestNG Suite to stop the whole run. Ending the attached VS Code debug session also stops its associated TestNG run and cleans up the debug process when possible.
Debug prerequisite:
- Install Extension Pack for Java by Microsoft
9) Use test category selection
The extension can detect TestNG groups from @Test(groups = ...) in Java files.
Relevant settings:
testngRunner.testCategoryMode = prompt
Prompts you to choose a detected group each time you run a suite. Cancelling the prompt cancels the run.
testngRunner.testCategoryMode = value
Always uses the saved testngRunner.testCategory.
testngRunner.testCategoryMode = all
Runs without passing -DtestCategory.
You can also run the command TestNG Runner: Select Test Category to choose and save a category from the current workspace.
For folder-level run or debug actions, category selection is resolved once for the whole batch instead of prompting once per suite.
10) Control headless mode and extra Maven arguments
Use these settings when your test framework needs them:
testngRunner.headless
Passes -Dheadless=true or -Dheadless=false
testngRunner.mavenArgs
Appends extra Maven arguments such as -Denv=qa
Troubleshooting
No suites found
- Make sure your project has one or more TestNG XML files whose root element is
<suite>.
- Click the refresh icon in the TestNG Runner sidebar.
Maven not found
- Either install Maven and add to PATH
- Or set Maven Home in settings
Java not found
- Either install JDK and set JAVA_HOME
- Or set Java Home in settings
Debug port 5005 is already in use
- Stop the active suite with Stop TestNG Suite or end its attached debug session, then retry.
- If another process owns the port, change
testngRunner.debugPort in Settings.
- On Windows, find the listener with
netstat -ano | findstr :5005, confirm the PID with tasklist /FI "PID eq <PID>", then stop that process with taskkill /F /PID <PID> if it is safe to do so. Check that the netstat row is LISTENING before acting; other rows may not represent an active listener.
Development
If you are working on the extension itself, use the steps below.
Build and run the extension locally
cd vscode-extension
npm install
npm run compile
Press F5 to launch an Extension Development Host window, then open a test workspace there and use the TestNG Runner view.
Common commands
npm run compile
npm run watch
npm run package
Use npm run watch if you are actively changing the extension code.
Where Are The Logs?
Each suite writes to its own log file.
The files are stored in VS Code's extension storage directory.
You can open them by right-clicking a suite and choosing Open TestNG Suite Log.
Changelog
Release notes are maintained in CHANGELOG.md.
Connect with me:
Kumar Priyank