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

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

  1. Open the automation project within VSCode
  2. Right-click on the "Maven" section in the sidebar
  3. Look for "Run Maven Commands" in the popup menu
  4. Select verify to 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

  1. Open the Test Explorer sidebar (flask icon)
  2. Navigate to your test classes
  3. 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

PhaseDescriptionCommand
cleanRemove previous build artifactsmvn clean
compileCompile source codemvn compile
testRun unit testsmvn test
verifyRun integration testsmvn verify
siteGenerate project documentationmvn 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

  1. Click in the gutter next to line numbers to set breakpoints
  2. Right-click on test method and select "Debug Test"
  3. 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:

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

⚠️ Maven Commands Not Found

Ensure Maven is in PATH and restart VSCode.

⚠️ Tests Not Discovered

Refresh Java projects: Cmd+Shift+P → "Java: Reload Projects"

⚠️ Allure Command Not Found

Install Allure via Homebrew: brew install allure

⚠️ Out of Memory Errors

Increase Maven memory: export MAVEN_OPTS="-Xmx2048m"

⚠️ HTTP Reports Not Generated

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

DocumentDescription
Test Development GuideWriting tests
Framework ArchitectureVisual overview
HTTP AssessmentSecurity auditing
Network DiagnosticsNetwork testing
mAi Advisor™Intelligent recommendations