Português (Brasil)

Automação e CI

Documentação

O ProbeTest aceita resultados automatizados em XML JUnit, enviados com curl simples. Os resultados viram execuções em um ciclo, atualizam o histórico de cada teste e sinalizam testes instáveis (flaky). O envio vai para um endereço hospedado pela Atlassian, exclusivo do seu site Jira.

1. Criar um token

  1. Abra CI results → Setup → Create token. Você precisa da permissão Administer projects.
  2. Informe um rótulo e, se quiser, uma validade. Em Also link requirements in other projects, escolha os projetos cujas histórias os resultados podem vincular.
  3. Copie o segredo (ptk_...). Ele é exibido uma única vez.

Você também pode gerenciar os tokens em Jira project settings → ProbeTest. Um token pode ser revogado a qualquer momento, e um projeto pode ter até 10 tokens.

Armazene estes valores como segredos no seu sistema de CI:

Segredo Valor
PROBETEST_URL O endereço de envio exibido na aba Setup. Trate-o como um segredo.
PROBETEST_TOKEN O token ptk_...

2. Enviar com curl

RUN_ID=build-123 REF_NAME=main          # your CI's run id and branch, as environment variables
RUN_Q=$(printf %s "$RUN_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128)
STREAM_Q=$(printf %s "$REF_NAME" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128)
curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" \
  -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" \
  --data-binary @reports/junit.xml

A etapa tr -c mantém apenas os caracteres aceitos pelo ProbeTest, de modo que um nome de branch malicioso não consiga alterar a requisição. Nunca cole no corpo do script uma expressão do CI para o nome de um branch, uma tag ou o título de um pull request. Mapeie-a para uma variável de ambiente e use-a como variável de shell entre aspas, como nos trechos abaixo.

Parâmetros de consulta:

Parâmetro Uso
runRef Uma execução de CI. Enviar o mesmo runRef e attempt duas vezes conta uma só vez.
attempt Um número maior para uma nova execução do CI. Um teste que passa em uma tentativa posterior é sinalizado como instável (flaky).
stream O nome do branch ou do pipeline
build, version O rótulo do build e uma versão do Jira à qual vincular o ciclo
cycle ou cycleName Acrescentar a um ciclo ou dar nome a um novo
dryRun=true Associa os resultados, mas não grava nada

Acrescente cada um como &name=$VALUE_Q, com o valor higienizado da mesma forma.

Trechos por provedor

Todos os trechos fazem a mesma chamada. A aba Setup os mostra com o seu endereço real.

GitHub Actions

- name: Upload results to ProbeTest
  if: always()
  env:
    RUN_ID: ${{ github.run_id }}
    REF_NAME: ${{ github.ref_name }}
    PROBETEST_URL: ${{ secrets.PROBETEST_URL }}
    PROBETEST_TOKEN: ${{ secrets.PROBETEST_TOKEN }}
  run: |
    RUN_Q=$(printf %s "$RUN_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128)
    STREAM_Q=$(printf %s "$REF_NAME" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128)
    curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" \
      -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" \
      --data-binary @reports/junit.xml

GitLab CI

upload_results:
  stage: .post
  when: always
  script:
    - 'RUN_Q=$(printf %s "$CI_PIPELINE_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128); STREAM_Q=$(printf %s "$CI_COMMIT_REF_NAME" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128); curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" --data-binary @reports/junit.xml'

Jenkins

post {
  always {
    withCredentials([string(credentialsId: 'probetest-token', variable: 'PROBETEST_TOKEN'), string(credentialsId: 'probetest-url', variable: 'PROBETEST_URL')]) {
      sh 'RUN_Q=$(printf %s "$BUILD_NUMBER" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128); STREAM_Q=$(printf %s "$BRANCH_NAME" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128); curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" --data-binary @reports/junit.xml'
    }
  }
}

Azure DevOps

- script: |
    RUN_Q=$(printf %s "$RUN_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128)
    STREAM_Q=$(printf %s "$REF_NAME" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128)
    curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" \
      -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" \
      --data-binary @reports/junit.xml
  displayName: Upload results to ProbeTest
  condition: always()
  env:
    RUN_ID: $(Build.BuildId)
    REF_NAME: $(Build.SourceBranchName)
    PROBETEST_URL: $(PROBETEST_URL)
    PROBETEST_TOKEN: $(PROBETEST_TOKEN)

CircleCI

- run:
    name: Upload results to ProbeTest
    when: always
    command: |
      RUN_Q=$(printf %s "$CIRCLE_WORKFLOW_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128); STREAM_Q=$(printf %s "$CIRCLE_BRANCH" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128); curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" --data-binary @reports/junit.xml

Bitbucket Pipelines

- step:
    name: Upload results to ProbeTest
    script:
      - 'RUN_Q=$(printf %s "$BITBUCKET_BUILD_NUMBER" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128); STREAM_Q=$(printf %s "$BITBUCKET_BRANCH" | tr -c "A-Za-z0-9._/-" _ | cut -c1-128); curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q&stream=$STREAM_Q" -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" --data-binary @reports/junit.xml'

Obter o XML JUnit da sua ferramenta de teste

Ferramenta Como
Playwright reporter: [['junit', { outputFile: 'reports/junit.xml' }]]
Cucumber (JVM e JS) --plugin junit:reports/junit.xml ou --format junit:reports/junit.xml
TestNG Nativo: test-output/junitreports/*.xml
pytest pytest --junitxml=reports/junit.xml
Jest Reporter jest-junit
JUnit, Maven, Gradle Surefire target/surefire-reports/*.xml, Gradle build/test-results/test/*.xml

Tamanho

Um corpo pode ter até 4 MB como está. Para arquivos maiores, compacte, codifique e adicione um cabeçalho:

gzip -9c reports/junit.xml | base64 | tr -d '\n' > junit.b64
RUN_Q=$(printf %s "$RUN_ID" | tr -c "A-Za-z0-9._:-" _ | cut -c1-128)
curl -sS --fail --proto =https -X POST "$PROBETEST_URL?runRef=$RUN_Q" \
  -H "Authorization: Bearer $PROBETEST_TOKEN" -H "Content-Type: application/xml" -H "X-Probetest-Encoding: gzip-base64" --data-binary @junit.b64

Divida uma suíte muito grande em vários arquivos com o mesmo runRef.

Respostas

Código Significado O que fazer
200 Concluído Nada
202 Aceito e na fila. O resultado aparece em até um minuto. Nada
401 Token ausente, incorreto, expirado ou revogado Verifique PROBETEST_TOKEN ou crie um novo token
429 Limite de requisições: 20 envios por minuto por site, 10 por minuto por token Aguarde 30 segundos e tente novamente
503 Temporariamente indisponível Tente novamente após 30 segundos

Um corpo XML malformado recebe uma mensagem de erro clara e não é armazenado em lugar nenhum.

Verificar se funcionou

Abra CI results → Pipelines. Cada envio é uma linha, com novas falhas, testes corrigidos, linhas rejeitadas e um link para o ciclo.

Como um resultado encontra o seu teste

O ProbeTest associa o nome do teste no relatório (classe e nome, no JUnit) a um teste da biblioteca. Para associar de forma explícita, adicione uma propriedade probetest com a chave do teste ou coloque-a no nome, por exemplo [KEY-T12]. Para vincular um requisito, adicione uma propriedade requirements ou coloque a chave da história no nome, por exemplo [SHOP-12].

O primeiro envio para um projeto cria os testes automatizados, e assim você já começa com histórico. Depois disso, um resultado sem teste correspondente vai para CI results → Unmatched. Ali você o associa a um teste existente, o que ensina o alias ao ProbeTest, ou cria um teste a partir dele. Nada é gravado em um teste até você decidir.

Abra CI results → Flaky para ver os testes que alternam de resultado ou só passam em uma nova tentativa. Os fluxos de pull request são mantidos no ciclo, mas não alteram a cobertura. Defina os fluxos de cobertura, por padrão main e main/*, em Jira project settings → ProbeTest.

Ações do Jira Automation

No Jira Automation, adicione uma ação e pesquise por ProbeTest:

  • ProbeTest - Create test cycle: cria um ciclo a partir de uma pasta, de um rótulo, de issues ou das execuções com falha e bloqueadas de outro ciclo.
  • ProbeTest - Get cycle summary: lê as contagens de um ciclo.
  • ProbeTest - Get release readiness: lê o veredito de uma versão.

Use as saídas em etapas seguintes, por exemplo, para publicar um resumo em um canal ou enviar por e-mail.