QA AND TEST AUTOMATION · PART 7 · BDD AND FRAMEWORK DESIGN · DESIGN · 71 OF 112

Test Reporting With Allure, and Logging That Helps

Making failures explain themselves: what a good test report shows, Allure with steps, labels, severity and attachments (run for real on ShopRung with pytest: the failing SAVE10 test shows which step failed and the API response), Allure in Java with JUnit 5, test logs with levels and request ids, secrets kept out, report history and trends in CI.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Readers first
  • Allure results → report
  • labels, steps, attachments
  • useful logs
  • history and categories

Notes

Who reads it

Think about who reads the report. A developer needs the failing step, the request and response, a screenshot and logs. A tester needs to know which rule and which data, and whether the test is flaky. A manager wants totals, the trend over time and what blocks a release. Plain console output serves none of them well, and it disappears with the CI machine.

One report, three readers
  • developer: which step failed, the request, the response, the screenshot, the logs
  • tester: which rule, which data, is it flaky?
  • manager: how many pass, trend over time, what is blocked
  • console output alone serves nobody well

How Allure works

Allure works in two stages. First, tests run with an Allure adapter for their framework: pytest, JUnit five, TestNG, Cucumber or Playwright. The adapter writes raw result files, one JSON file per test plus attachments, into an allure results folder. Second, the Allure command line turns that folder into a static HTML report. Because results are just files, CI can merge results from many shards into one report.

Two stages
1 run tests with an Allure
  adapter (pytest, JUnit 5,
  TestNG, Cucumber, Playwright)
  → allure-results/*.json
2 allure generate
    allure-results -o allure-report
  → static HTML site

npx allure generate ... (CLI
  needs Java)

Steps and labels

In the test, labels group results: feature coupons, story save ten, severity critical. Steps describe what happens, in business words: add four notebooks, apply save ten, check the total. Attachments add evidence; here the coupon response body is attached as JSON. Steps and attachments are what turn a stack trace into a story a developer can follow.

pytest + allure-pytest
@allure.feature("Coupons")
@allure.story("SAVE10")
@allure.severity(CRITICAL)
def test_save10_at_50(alice):
  with allure.step("Add 4 notebooks"):
    alice.post("/api/cart/items",..)
  with allure.step("Apply SAVE10"):
    r = alice.post(".../coupon", ..)
    allure.attach(r.text, "coupon
      response", JSON)
  with allure.step("Check total")...

A real report

We ran this test with ShopRung's coupon boundary bug on and generated the report. Under behaviors, coupons, save ten, the test is failed and marked critical. The first two steps passed, the third failed with assert four hundred equals two hundred, and the attached coupon response holds the shop's reason. Anyone can see where it broke and why, without running anything.

What the report showed
Behaviors › Coupons › SAVE10
test_save10_at_50  FAILED
  severity: critical
  ✔ Add 4 notebooks ($50.00)
  ✔ Apply SAVE10
      📎 coupon response (JSON)
  ✘ Check the total is $49.99
AssertionError: assert 400 == 200

In Java

In Java, add the Allure JUnit five adapter. Annotations give the same labels: feature, story, severity. Allure dot step wraps a lambda as a named step, and add attachment adds a body, a log or a screenshot. Many teams also use the step annotation on page object methods, which needs AspectJ configured in Surefire, so every user action appears as a step automatically. Cucumber scenarios become steps without extra code.

JUnit 5 + Allure
// io.qameta.allure:allure-junit5
@Feature("Coupons") @Story("SAVE10")
@Severity(SeverityLevel.CRITICAL)
@Test void save10At50() {
  Allure.step("Add 4 notebooks",
    () -> cart.add(NOTEBOOK, 4));
  var r = Allure.step("Apply SAVE10",
    () -> cart.coupon("save10"));
  Allure.addAttachment("response",
    "application/json", r.body());
}

Logging

Logs complement reports. Use levels: debug for detail, info for actions, warn and error for problems. Log actions and the ids of data you create, like order ten forty two created, so a failure can be traced. Send a request id header with API calls and log it, so the developer can find the same request in the server's logs. Never log passwords, tokens or card numbers; mask them. And attach each test's own log to its report entry on failure.

Useful test logs
  • levels: DEBUG detail, INFO actions, WARN, ERROR
  • log actions and data ids: "order 1042 created"
  • send and log a request id (X-Request-Id) to find the server side in its logs
  • never log passwords, tokens, card numbers: mask them
  • per test, attached on failure

Common mistakes

Mistakes. Reports that vanish with the CI job. Steps named step one or click, which say nothing. Screenshots and videos for every passing test, making reports huge. Secrets in logs or attachments, which then get shared widely. Huge logs with no levels. And bug tickets with no link to the report, so everyone reruns the test anyway.

Avoid these
  • reports nobody can open after the CI job ends
  • steps named "step 1", "click"
  • screenshots for passing tests (huge reports)
  • secrets in logs or attachments
  • giant logs with no levels
  • no link from bug to report

Say it like this

In the interview: I use Allure through the framework's adapter, with features, stories and severity, steps named in business terms, and attachments on failure: the request and response, a screenshot, and the test's own log with request ids, secrets masked. CI publishes the report for every run with history, so trends and flaky tests are visible, and bug tickets link straight to the failing entry.

In the interview
  • "Allure from the test adapter: features, stories, severity, business-named steps, and attachments on failure: request and response, screenshot, per-test log with request ids, secrets masked.
  • CI publishes it per run with history, so trends and flaky
  • tests are visible."

Interview questions

Q1What is Allure?

A test reporting tool: framework adapters write raw results (JSON plus attachments) and the Allure CLI generates an HTML report with steps, labels, attachments, history and categories.

Q2How do you add steps and attachments in Allure?

Python: with allure.step(...) and allure.attach(...). Java: Allure.step(name, lambda), @Step on methods (with AspectJ), and Allure.addAttachment(...).

Q3What should a failed test report contain?

The failing step, expected versus actual, request and response or a screenshot, the test's log, environment and data ids.

Q4How do you keep Allure history across CI runs?

Copy the history folder from the previous report into allure-results before generating, so trends and flaky markers appear.

Q5What are Allure categories?

Rules (by status and message regex) that group failures, for example product defects, test defects and environment issues.

Q6What makes test logs useful?

Levels, actions with data ids, request ids that match server logs, per-test logs attached on failure, and masked secrets.

Q7Why not just use console output?

It is hard to read, not grouped by test, lacks evidence and disappears with the CI machine.

Q8How do you combine results from parallel or sharded runs?

Collect every shard's allure-results into one folder, then generate a single report.