Skip to main content
Skip table of contents

Bitbucket

Bitbucket is one of the widely known CI/CD tool. In this document, we will show you how to integrate AgileTest with Bitbucket via REST API.

However, in order to utilize AgileTest API, Client id and Client secret are needed. Please refer to this instruction to get them first Access API documentation.

Make sure your account has permission to create TestCase and TestExecution issues; otherwise, the import will fail.

Setup with Bitbucket

In your Bitbucket repository, go to Repository settingsRepository variables and create respective repository variables for acquired client id and client secret.

In this example, we will create 3 repository variables CLIENT_ID, CLIENT_SECRET, and PROJECT_KEY

image (66).png

Repository variable screen

Upload test result

Here is a JUnit report example to play around with.

JUnit report example
XML
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="15" failures="0" name="ut.com.xpandit.raven.service.impl.IssueDataSetTest" time="0.163" errors="0" skipped="0">
  <properties>
    ...
  </properties>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitOverflowOption_returnsExpectedSubset" time="0.114"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withNullOptionsAndValidIssue_throwsIllegalArgumentException" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidEmptyOptions_returnsAllIssues" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptions_returnsExpectedTests" time="0.016"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndInvalidColumnSearchOption_returnsAllTests" time="0.007"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidLimitUnderOption_returnsExpectedSubset" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesIssueKey_returnsExpectedTestWithMatchedKey" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.006"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidSummaryColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMatchesAllElements_returnsAllTests" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesOneElement_returnsOneTest" time="0.002"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidColumnSearchOptionThatMatchesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidGlobalSearchOptionThatMachesNoIssue_returnsEmptyList" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnDescSortOption_returnsExpectedIssuesInDescOrder" time="0.001"/>
  <testcase classname="ut.com.xpandit.raven.service.impl.IssueDataSetTest" name="testApplyOptions_withValidIssueAndValidKeyColumnAscSortOption_returnsExpectedIssuesInAscOrder" time="0.001"/>
</testsuite>

If you need more detailed examples, please refer to our public repository on AgileTest GitHub for additional sample projects.

Use API

Below is a sample bitbucket-pipelines.yml file.

YAML
image: mcr.microsoft.com/dotnet/sdk
options:
  docker: true

definitions:
  steps:
    - step: &linting
        name: Linting
        caches:
          - dotnetcore
        script:
          - echo "linting"

pipelines:
  pull-requests:
    develop:
      - step: *linting
    master:
      - step: *linting

  # TODO: build docker image
  branches:
    nunit:
      # - step: *linting
      - step: &run-test
          name: Run test
          script:
            - cd ./Nunit/PrimeService && dotnet restore
            - cd .. && dotnet sln add PrimeService/PrimeService.csproj
            - cd ./PrimeService.Tests && dotnet restore
            - cd .. && dotnet sln add PrimeService.Tests/PrimeService.Tests.csproj
            - dotnet test --logger:"nunit;LogFilePath=test-result.xml"
            - export token=$(curl 'https://agiletest.atlas.devsamurai.com/api/apikeys/authenticate' -X POST -H 'Content-Type:application/json' --data '{"clientId":"'"$CLIENT_ID"'","clientSecret":"'"$CLIENT_SECRET"'"}' | tr -d '"')
            - echo $token
            - curl -X POST -H "Content-Type:application/xml" -H "Authorization:JWT $token" --data-binary "@PrimeService.Tests/test-result.xml" "https://api.agiletest.app/ds/test-executions/nunit?projectKey=$PROJECT_KEY"

In this file, we use 2 endpoints

  • api/v1/apikeys/authenticate to get temporary token using acquired client_id and client_secret.

  • ds/test-executions/nunit to submit test report to Agile Test so that the application could create or update Test execution and Test cases accordingly.

To learn more about these endpoints, please refer to this document API document.

Use AgileTest CLI

YAML
image: mcr.microsoft.com/dotnet/sdk
options:
  docker: true

definitions:
  steps:
    - step: &linting
        name: Linting
        caches:
          - dotnetcore
        script:
          - echo "linting"

pipelines:
  pull-requests:
    develop:
      - step: *linting
    master:
      - step: *linting

  branches:
    nunit:
      - step: &run-test
          name: Run test
          script:
            - cd ./Nunit/PrimeService && dotnet restore
            - cd .. && dotnet sln add PrimeService/PrimeService.csproj
            - cd ./PrimeService.Tests && dotnet restore
            - cd .. && dotnet sln add PrimeService.Tests/PrimeService.Tests.csproj
            - dotnet test --logger:"nunit;LogFilePath=test-result.xml"
          artifacts:
            - Nunit/PrimeService.Tests/*.xml
      - step: &upload-report
          name: Upload report to AgileTest using cli
          image: ghcr.io/agiletestapp/agiletest-cli:latest
          script:
            - agiletest --client-id $CLIENT_ID --client-secret $CLIENT_SECRET \
              test-execution import \
              --framework-type nunit --project-key $PROJECT_KEY \
              $BITBUCKET_CLONE_DIR/Nunit/PrimeService.Tests/test-result.xml

In this file, we configure 2 steps, run-test and upload-report. Each step runs in a container of different image. For run-test, we use dotnet image, but in upload-report, the docker image is actually the one built for Agile Test CLI.

In run-test step, we run the automation test scripts and the process yields the reports. Then, in upload-report step, the report is uploaded to Agile Test by using AgileTest CLI. Below is the command used for the task.

BASH
agiletest --client-id ${CLIENT_ID} --client-secret ${CLIENT_SECRET} \
              test-execution import \
              --framework-type nunit --project-key ${PROJECT_KEY} \
              $BITBUCKET_CLONE_DIR/Nunit/PrimeService.Tests/test-result.xml

For each test run, a new Test Execution will be created along with linked Test Cases. However, if the Test Cases already exist in your project, Agile Test will only generate a new Test Execution and link the matching Test Cases to it, including the test results


Should you need any assistance or further AgileTest inquiries, contact here!

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.