Sobes.tech
Middle

Have you worked with Allure? What annotations can you name? Is it possible to attach a screenshot and how? Where are the test run results stored? How to integrate Allure with CI/CD (Jenkins)?

sobes.tech AI

Answer from AI

Allure is a popular framework for generating beautiful and informative test result reports.

Annotations in Allure (example in Java, but the concept is similar in other languages):

  • @Step — for describing test steps
  • @Attachment — for attaching files (screenshots, logs)
  • @Feature, @Story — for grouping tests by functionality
  • @Severity — for indicating the importance of a test

Attach a screenshot:

@Attachment(value = "Screenshot", type = "image/png")
public byte[] saveScreenshot(byte[] screenShot) {
    return screenShot;
}

You can call this method in a test, passing the screenshot bytes, to include it in the report.

Where are the test results stored? Allure saves the results as a set of files (JSON, XML, attachments) in the allure-results folder (by default). Then, an HTML report is generated from this data.

Integration with CI/CD (e.g., Jenkins):

  1. The test run is initiated in Jenkins, which saves the results in allure-results.
  2. After the run, the report is generated using the command allure generate.
  3. The report is published using the Allure Jenkins Plugin.

Example Jenkins pipeline:

stage('Test') {
    steps {
        sh './gradlew test'
    }
}
stage('Allure Report') {
    steps {
        allure includeProperties: false, results: [[path: 'build/allure-results']]
    }
}

Thus, Allure allows convenient visualization of test results, attaching artifacts, and integration with CI/CD systems.