Introducing the Schema of Allure Report Tool

18/Dec/2022 · 4 minute read

Background

In October, I claimed an issue on the company’s internal open source collaboration project. The task was to implement a test report visualization tool for the internal test framework. Because the display effect of Allure is really good, but there is no official detailed description of the underlying schema, so there are some gropings in the implementation process, and it is recorded here, hope it can help someone who may encounter similar problems.

What is Allure Report?

Allure,the full name of which is Allure Report,is a cross programming languages test report tool. The framework provides multiple adapters and bindings in different languages with the underlying and standard schema. It currently supports Java, JavaScript, Python, Ruby, PHP, Kotlin, .Net, and Go。

Allure is capable to generate clean test reports, which consist of Overview, Categories, Suites, Graphs, Timeline, Behaviors and Packages pages, you can visit Allure demo to see the official demo. If you wanna view more different examples, please visit RESTest showcase.

allure demo

Additionally, Allure supports multiple locales,currently, the official project supports 12 languages, including English and Chinese。

Allure implements the whole ecosystem based on different programming languages.

allure architecture

Allure Schema

Thanks to the JSON-based and language-independent schema, Allure implements the standard in different languages. For example, you can visit allure-python-commons/src/model2.py to view a Python version.

However, the official team doesn’t provide detailed document about how to use the schema, so it is hard to understand how will the schema affects the final report. By trying and debugging, I have summarized the diagram to show all models and the relationships among them.

allure models

A Detailed Demo

For references between the schema and the final report, you can start from the below codes which is a basic allure test case:

{
    "name": "test_shell_testcase_failed32",  // The name of the test case
    "status": "failed", // the result of the test case,its enumerations are defined by the `Status`
    "steps": [ // The steps of the test,they are shown in the section "Test body" in the report
        {
            "name": "#@ 测试步骤:17:",
            "status": "passed"
        },
        {
            "name": "#@ 测试步骤:28:",
            "status": "passed"
        },
        {
            "name": "#@ 测试步骤:39:",
            "status": "passed"
        }
    ],
    "start": "1665562034999",  // The beginning time of the test case
    "stop": "1665562053613",   // The ending time of the test case,it is used to calculate the elapsed time with the beginning time,for instance, it is 18s 614ms here
    "uuid": "test_python_testcase-result-37", // uuid,it should be generated by official libraries
    "testCaseId": "20220411-152848-724647399", // it should be generated by official libraries, too
    "labels": [
        {
            "name": "suite",  // suite means it is a special label,its value is used to represent the suite name of cases
            "value": "tst_suite_common2"
        },
        {
            "name": "tag",  // normal labels, labels are listed in the details of the test case report
            "value": "feature"
        },
        {
            "name": "tag",
            "value": "medium priority"
        },
        {
            "name": "tag",
            "value": "level:3"
        },
        {
            "name": "tag",
            "value": "type:feature"
        }
    ]
}

the below shows the report corresponding to the above schema:

allure case report

How to generate Allure schema by official libraries?

Assume you are using Python,you can use AllureFileLogger, which is a module in allure-python-commons official library.

The belows shows a simple example:

from allure_commons.logger import AllureFileLogger
from allure_commons.model2 import TestResult, Status, Label, Link
from allure_commons.types import LinkType
from allure_commons.utils import now, uuid4

if __name__ == "__main__":
    logger = AllureFileLogger(report_dir="tmp/logger_reports/")
    result = TestResult(
        name="test case",
        status=Status.PASSED,
        # statusDetails="test passed",
        stage="local test",
        description="simulation test",
        descriptionHtml="<h1>simulation test</h1>",
        start=now()-3000,
        stop=now(),
        uuid=uuid4(),
        historyId=uuid4(),
        testCaseId=uuid4(),
        fullName="a fake test case demo",
        labels=[Label(name="owner", value="martinhong"), Label(name="weight", value="highest")],
        links=[Link(type=LinkType.ISSUE,url="https://google.com.hk",name="fake link")])
    logger.report_result(result)

It can generates the below schema:

{
    "name": "test case",
    "status": "passed",
    "stage": "local test",
    "description": "simulation test",
    "descriptionHtml": "<h1>simulation test</h1>",
    "start": 1664635107494,
    "stop": 1664635110494,
    "uuid": "083c72da-668c-406c-a258-ba61f2eec2f2",
    "historyId": "c665bc04-9b63-426f-a7ce-b1981853d775",
    "testCaseId": "2b53d7b0-2127-46ab-8c72-ec2e5c97b759",
    "fullName": "a fake test case demo",
    "labels": [
        {
            "name": "owner",
            "value": "martinhong"
        },
        {
            "name": "weight",
            "value": "highest"
        }
    ],
    "links": [
        {
            "type": "issue",
            "url": "https://google.com.hk",
            "name": "fake link"
        }
    ]
}

Its corresponding report is:

allure simple case

References

版权声明:本文为原创文章,转载请注明来源:《Introducing the Schema of Allure Report Tool - Hackerpie》,谢绝未经允许的转载。