Azure DevOps

Tento navod vysvetluje, ako integrovat LoadFocus JMeter API klienta s Azure DevOps na automatizovane testovanie vykonnosti.

Kroky nastavenia

1. Ulozenie povereni v Azure Key Vault

Pre bezpecnu spravu povereni ulozte vase poverenia LoadFocus API v Azure Key Vault:

  1. Vytvorte Key Vault v Azure, ak este nemate
  2. Pridajte nasledujuce tajomstva:
    • loadfocus-api-key: Vas LoadFocus API kluc
    • loadfocus-team-id: Vase LoadFocus team ID
  3. Nastavte servisne pripojenie pre pristup k Key Vault z vasho pipeline

2. Vytvorenie Azure Pipeline

Vytvorte novy subor s nazvom azure-pipelines.yml vo vasom repozitari:

trigger:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
variables:
- group: loadfocus-variables # Variable group containing Key Vault references
stages:
- stage: Build
jobs:
- job: BuildAndTest
steps:
# Your existing build and test steps...
- stage: PerformanceTest
dependsOn: Build
condition: succeeded()
jobs:
- job: RunPerformanceTests
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
npm install -g @loadfocus/loadfocus-api-client
displayName: 'Install LoadFocus JMeter API Client'
- script: |
loadfocus-api config set apikey $(LOADFOCUS_API_KEY)
loadfocus-api config set teamid $(LOADFOCUS_TEAM_ID)
displayName: 'Configure LoadFocus API Client'
- script: |
loadfocus-api jmeter run-test \
--name "AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)" \
--thresholds "avgresponse<=200,errors==0,p95<=250" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'performance-test-results'
displayName: 'Publish Performance Test Results'
- stage: Deploy
dependsOn: PerformanceTest
condition: succeeded()
jobs:
- job: DeployApplication
steps:
# Your deployment steps...

3. Nastavenie skupiny premennych s integraciou Key Vault

  1. Prejdite na Pipelines > Library > Variable Groups
  2. Vytvorte novu skupinu premennych s nazvom "loadfocus-variables"
  3. Prepojte ju s vasim Azure Key Vault
  4. Pridajte nasledujuce premenne, prepojte ich s vasimi tajomstvami Key Vault:
    • LOADFOCUS_API_KEY: Prepojte na tajomstvo loadfocus-api-key
    • LOADFOCUS_TEAM_ID: Prepojte na tajomstvo loadfocus-team-id

Pokrocila konfiguracia

Pouzitie YAML sablon

Pre opakovanepouzitelne kroky testovania vykonnosti vytvorte subor sablony performance-test-template.yml:

parameters:
testName: 'Default_Test'
thresholds: 'avgresponse<=200,errors==0,p95<=250'
waitTimeout: 1800
steps:
- script: |
loadfocus-api jmeter run-test \
--name "${{ parameters.testName }}" \
--thresholds "${{ parameters.thresholds }}" \
--waitTimeout ${{ parameters.waitTimeout }} \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false

Potom vo vasom hlavnom pipeline:

- template: performance-test-template.yml
parameters:
testName: 'AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)'
thresholds: 'avgresponse<=150,errors==0,p95<=200'
waitTimeout: 2400

Spustenie viacerych testov

Na spustenie viacerych testov vykonnosti za sebou:

- script: |
# Run API test
loadfocus-api jmeter run-test \
--name "API_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/api_test_results.json
# Run UI test
loadfocus-api jmeter run-test \
--name "UI_Test" \
--thresholds "avgresponse<=500,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/ui_test_results.json
displayName: 'Run Multiple Performance Tests'

Integracia s Azure Test Plans

Na integraciu vysledkov testov vykonnosti s Azure Test Plans:

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(Build.ArtifactStagingDirectory)/test-results.xml'
testRunTitle: 'Performance Tests'
displayName: 'Publish Test Results'
condition: succeededOrFailed()

Budete musiet konvertovat JSON vystup do formatu JUnit:

- script: |
# Run performance test
loadfocus-api jmeter run-test \
--name "AzureDevOps_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
# Convert JSON to JUnit format (using a custom script)
node convert-to-junit.js \
$(Build.ArtifactStagingDirectory)/performance_results.json \
$(Build.ArtifactStagingDirectory)/test-results.xml
displayName: 'Run Performance Tests and Convert Results'

Tipy pre integraciu Azure DevOps

  1. Paralelne ulohy: Ak mate viacero testov vykonnosti, zvazte pouzitie paralelnych uloh:

    jobs:
    - job: API_Performance_Test
    steps:
    # Run API performance test
    - job: UI_Performance_Test
    steps:
    # Run UI performance test
  2. Brany nasadenia: Pouzite vysledky testov vykonnosti ako branu nasadenia:

    - job: DeploymentGate
    steps:
    - script: |
    # Check if performance tests passed
    if grep -q '"overallResult": "FAILED"' $(Build.ArtifactStagingDirectory)/performance_results.json; then
    echo "##vso[task.logissue type=error]Performance tests failed"
    echo "##vso[task.complete result=Failed;]"
    fi
  3. Vlastny dashboard: Vytvorte vlastny dashboard na vizualizaciu vysledkov testov vykonnosti v priebehu casu.

  4. Notifikacie: Nastavte notifikacie pre zlyhania testov vykonnosti:

    - task: SendEmail@1
    inputs:
    to: 'team@example.com'
    subject: 'Performance Test Failed'
    body: 'Performance tests failed to meet thresholds. See attached results.'
    addAttachment: true
    attachmentPath: '$(Build.ArtifactStagingDirectory)/performance_results.json'
    condition: failed()

Pre viac informacii pozrite dokumentaciu Azure DevOps a dokumentaciu LoadFocus API klienta.