Test Execution in VSCode
Running test automation with Maven within Visual Studio Code
This guide covers various methods for executing tests within VSCode ? and generating reports using Maven ? and Allure ?.
VSCode Setup
Required Extensions
- Java Extension Pack - Microsoft (Core Java support)
- Maven for Java - Microsoft (Maven integration)
- Test Runner for Java - Microsoft (Test execution UI)
- XML - Red Hat (POM file support)
Workspace Settings
Ensure your .vscode/settings.json includes:
{
"java.home": "/opt/homebrew/opt/openjdk/",
"java.configuration.updateBuildConfiguration": "automatic",
"java.debug.settings.onBuildFailureProceed": true
}
Running Tests via Maven
Method 1: Maven Sidebar
- Open the automation project within VSCode
- Right-click on the "Maven" section in the sidebar
- Look for "Run Maven Commands" in the popup menu
- Select
verifyto execute all tests and generate reports
Method 2: Terminal Commands
Open the integrated terminal (Terminal > New Terminal) and run:
# Run all tests
mvn verify
# Run specific test suite
mvn test -Dtest=TS_Authentication_JUnit
# Run specific test method
mvn test -Dtest=TS_Authentication_JUnit#testValidLogin
# Run HTTP security assessment
mvn test -Dtest=TS_HttpAssessment_JUnit
# Run network diagnostics
mvn test -Dtest=TS_Network_JUnit
# Run with specific browser
mvn test -Dbrowser=chrome
# Run with custom configuration
mvn test -DconfigFile=test-staging.properties
Method 3: Test Explorer
- Open the Test Explorer sidebar (flask icon)
- Navigate to your test classes
- Click the play button next to: Package level (all tests), Class level (class tests), or Method level (single test)
Method 4: Code Lens
With Java extensions installed, you'll see "Run Test" and "Debug Test" links above test classes and test methods. Click these to execute tests directly from the editor.
Maven Lifecycle Phases
| Phase | Description | Command |
|---|---|---|
clean | Remove previous build artifacts | mvn clean |
compile | Compile source code | mvn compile |
test | Run unit tests | mvn test |
verify | Run integration tests | mvn verify |
site | Generate project documentation | mvn site |
Launching Allure Report
Generate and Open Report
# 1. Navigate to project root
cd ~/Documents/Development/Automation/Automation-Projects/Automation-JAV-SwagLabs
# 2. Run tests
mvn verify
# 3. Generate and open Allure report
allure open
# 4. Press Ctrl+C in terminal to stop the server
Alternative: Generate Static Report
# Generate report without server
allure generate --clean
# Open in browser manually
open allure-report/index.html
Launching JavaDocs
# Navigate to project root
cd ~/Documents/Development/Automation/Automation-Projects/Automation-JAV-SwagLabs
# Generate JavaDocs
mvn site
# Open in Chrome
open -a "Google Chrome" target/site/index.html
# Or use default browser
open target/site/index.html
Debugging Tests
Setting Breakpoints
- Click in the gutter next to line numbers to set breakpoints
- Right-click on test method and select "Debug Test"
- Use Debug Console to inspect variables
Debug Configuration
Create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug Current Test",
"request": "launch",
"mainClass": "",
"projectName": "Automation-JAV-SwagLabs"
}
]
}
Remote Debugging
For Maven Surefire ? debugging:
mvn -Dmaven.surefire.debug test
# Then attach debugger on port 5005
Test Execution Options
Parallel Execution
# Run tests in parallel
mvn test -Djunit.jupiter.execution.parallel.enabled=true
Skip Tests
# Build without running tests
mvn install -DskipTests
# Skip test compilation and execution
mvn install -Dmaven.test.skip=true
Test Filtering
# Run tests with specific tags
mvn test -Dgroups="smoke"
# Exclude tests with tags
mvn test -DexcludedGroups="slow"
Advanced Feature Tests
HTTP Security Assessment
Run comprehensive HTTP security audits:
# Run HTTP assessment suite
mvn test -Dtest=TS_HttpAssessment_JUnit
# Run specific HTTP audit
mvn test -Dtest=TS_HttpAssessment_JUnit#testHttpSecurityHeaders
View HTTP diagnostic reports:
- Location:
target/http-reports/ - HTML report with color-coded findings
- Includes mAi Advisor™ recommendations
Network Diagnostics
Run network connectivity and performance tests:
# Run all network tests
mvn test -Dtest=TS_Network_JUnit
# Run ping test only
mvn test -Dtest=TS_Network_JUnit#testPing
# Run traceroute only
mvn test -Dtest=TS_Network_JUnit#testTraceroute
# Run speed test only
mvn test -Dtest=TS_Network_JUnit#testSpeedTest
Cleaning Build Artifacts
Complete Clean
# Remove all generated files
mvn clean
This removes: target/ directory, test reports, compiled classes, JavaDocs, Allure results, and HTTP diagnostic reports.
Selective Clean
# Clean only Allure results
rm -rf allure-results/
# Clean only reports
rm -rf allure-report/
# Clean only JavaDocs
rm -rf target/site/
# Clean HTTP reports
rm -rf target/http-reports/
Common Issues and Solutions
Ensure Maven is in PATH and restart VSCode.
Refresh Java projects: Cmd+Shift+P → "Java: Reload Projects"
Install Allure via Homebrew: brew install allure
Increase Maven memory: export MAVEN_OPTS="-Xmx2048m"
Ensure target directory exists and tests completed successfully.
Tips and Tricks
Quick Commands (Shell Aliases)
Add to ~/.zshrc or ~/.bash_profile:
alias test-all="mvn clean verify"
alias test-smoke="mvn test -Dgroups=smoke"
alias test-http="mvn test -Dtest=TS_HttpAssessment_JUnit"
alias test-network="mvn test -Dtest=TS_Network_JUnit"
alias report="allure open"
alias docs="mvn site && open target/site/index.html"
VSCode Tasks
Create .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run All Tests",
"type": "shell",
"command": "mvn clean verify",
"group": "test"
},
{
"label": "Run HTTP Assessment",
"type": "shell",
"command": "mvn test -Dtest=TS_HttpAssessment_JUnit",
"group": "test"
},
{
"label": "Run Network Tests",
"type": "shell",
"command": "mvn test -Dtest=TS_Network_JUnit",
"group": "test"
},
{
"label": "Generate Report",
"type": "shell",
"command": "allure open",
"group": "build"
}
]
}
Next Steps
| Document | Description |
|---|---|
| Test Development Guide | Writing tests |
| Framework Architecture | Visual overview |
| HTTP Assessment | Security auditing |
| Network Diagnostics | Network testing |
| mAi Advisor™ | Intelligent recommendations |