Skip to main content

用于将测试结果序列化到 SQL 数据库的工具

项目描述

测试存档

TestArchiver 是一个用于将测试结果归档到 SQL 数据库的工具。

Epimetheus是浏览您归档的结果的工具

测试框架支持

框架 地位 夹具测试状态 解析器选项
机器人框架 支持的 完毕 机器人
摩卡 支持的 完毕 摩卡君
pytest 支持的 完毕 pytest-junit
PHPUnit 支持的 完毕 php-junit
JUnit 实验性的 失踪 朱尼特
xUnit 实验性的 失踪 xunit
测试 实验性的 失踪 测试

这里的实验状态意味着有一个解析器可以接收例如通用 JUnit 格式的输出,但没有特定的测试集或任何广泛的测试或解析器的积极开发。

对不同测试框架的输出解析器或侦听器的贡献表示赞赏。简单地贡献一个夹具测试集(可用于生成用于开发特定解析器的输出文件)对于任何新框架都非常有帮助。

安装

sudo -H python3 -m pip install testarchiver

支持的数据库

SQLite

存档器的SQLite默认数据库,主要用于测试和演示目的。Sqlite3 驱动程序是 python 标准库的一部分,因此没有额外的依赖项来试用存档器。

PostgreSQL

PostgreSQL是当前实际项目支持的数据库。例如Epimetheus服务使用 PosrgreSQL 数据库。为了访问 PostgreSQL 数据库,脚本使用 psycopg2 模块:(pip install psycopg2-binary带有 pip install )

基本用法

test_archiver/output_parser.py可以使用脚本将来自不同测试框架的输出文件解析到数据库中。

testarchiver --database test_archive.db output.xml

假设这output.xml是由 Robot Framework(默认解析器选项)生成的输出文件,这将创建一个名为test_archive.db包含结果的 SQLite 数据库文件。

有关其他选项的列表:testarchiver --help

positional arguments:
  output_files          list of test output files to parse in to the test
                        archive

optional arguments:
  -h, --help            show this help message and exit
  --version, -v         show program's version number and exit
  --config CONFIG_FILE  Path to JSON config file containing database
                        credentials and other configurations. Options given on
                        command line will override options set in a config
                        file.
  --format {robot,robotframework,xunit,junit,mocha-junit,pytest-junit,mstest,php-junit}
                        output format (default: robotframework)
  --repository REPOSITORY
                        The repository of the test cases. Used to
                        differentiate between test with same name in different
                        projects.
  --team TEAM           Team name for the test series
  --series SERIES       Name of the test series (and optionally build number
                        'SERIES_NAME#BUILD_NUM' or build id
                        'SERIES_NAME#BUILD_ID')
  --metadata NAME:VALUE
                        Adds given metadata to the test run. Expected format:
                        'NAME:VALUE'

Database connection:
  --dbengine DB_ENGINE  Database engine, postgresql or sqlite (default)
  --database DATABASE   database name
  --host HOST           database host name
  --user USER           database user
  --pw PASSWORD, --password PASSWORD
                        database password
  --port PORT           database port (default: 5432)
  --dont-require-ssl    Disable the default behavior to require ssl from the
                        target database.

Schema updates:
  --allow-minor-schema-updates
                        Allow TestArchiver to perform MINOR (backwards
                        compatible) schema updates the test archive
  --allow-major-schema-updates
                        Allow TestArchiver to perform MAJOR (backwards
                        incompatible) schema updates the test archive

Limit archived data:
  --no-keywords         Do not archive keyword data
  --no-keyword-stats    Do not archive keyword statistics
  --ignore-logs-below {TRACE,DEBUG,INFO,WARN}
                        Sets a cut off level for archived log messages. By
                        default archives all available log messages.
  --ignore-logs         Do not archive any log messages
  --max_log_message_length MAX_LOG_MESSAGE_LENGTH
                        Specify how many characters of the log message that is
                        archived. full: archives the complete log. positive
                        integers: archives number of characters from the
                        beginning. negative integers: archives number of
                        characters from the end.

Adjust timestamps:
  --time-adjust-secs TIME_ADJUST_SECS
                        Adjust time in timestamps by given seconds. This can
                        be used to change time to utc before writing the
                        results to database, especially if the test system
                        uses local time, such as robot framework. For example
                        if test were run in Finland (GMT+3) in summer (+1hr),
                        calculate total hours by minutes and seconds and
                        invert to adjust in correct direction, i.e.
                        -(3+1)*60*60, so --time-adjust-secs -14400. This
                        option is useful if you are archiving in a different
                        location to where tests are run.If you are running
                        tests and archiving in same timezone, time-adjust-
                        with-system-timezone may be a better option. This
                        option may be used in conjunction with --time-adjust-
                        with-system-timezone if desired.
  --time-adjust-with-system-timezone
                        Adjust the time in timestamps by the system timezone
                        (including daylight savings adjust). If you are
                        archiving tests in the same timezone as you are
                        running tests, setting this option will ensure time
                        written to the database is in UTC/GMT time. This
                        assumes that if multiple computers are used that their
                        timezone and daylight savings settings are identical.
                        Take care also that you do not run tests just before a
                        daylight savings time adjust and archive just after,
                        as times will be out by one hour. This could easily
                        happen if long running tests cross a timezone adjust
                        boundary. This option may be used in conjunction with
                        --time-adjust-secs.

ChangeEngine:
  --change-engine-url CHANGE_ENGINE_URL
                        Starts a listener that feeds results to ChangeEngine
  --execution-context EXECUTION_CONTEXT
                        To separate data from different build pipelines for
                        ChangeEngine prioritization. Example if same changes
                        or tests may be used to verify app in Android and iOS
                        platforms, then it would be good to separate the
                        result from different builds pipelines/platforms. The
                        ChangeEngine prioritization might not give correct
                        result if different results from different platforms
                        are mixed together.
  --changes CHANGES     Json file which contains information from the changed
                        files for each repo. The file should be formatted like
                        this: { "context": "The execution context, same as
                        --execution-context and command line will override
                        this setting.", "changes": [ { "name": "string
                        representing the changed item, for example file path",
                        "repository": "Repository (optional), for separating
                        between changed items with identical names.",
                        "item_type": "Separating items (optional) and for
                        filtering subsets when prioritising", "subtype":
                        "(optional, for separating items for filtering subsets
                        when prioritising" } ] }
  --execution-id EXECUTION_ID
                        Identifier or version of the tested application for
                        given execution-context. Stored in ChangeEngine and
                        returned by "last_update" query.

数据模型

模式和数据模型(注意:这指向最新版本)

有用的元数据

有一些元数据可用于添加结果。一些测试框架允许将元数据添加到您的测试结果中,对于那些框架(例如机器人框架),建议将元数据添加到测试中,以便结果中也可以使用相同的信息。--metadata使用该选项解析结果时,可以添加其他元数据。解析期间给出的元数据链接到顶级测试套件。

--metadata NAME:VALUE

测试系列和团队

在数据模型中,每个测试结果文件都表示为单个测试运行。这些测试运行被链接并组织成不同结果系列中的构建。根据情况,该系列可以是例如 CI 构建作业或不同的分支。默认情况下,如果未指定系列,则结果将链接到具有自动递增内部版本号的默认系列。可以将属于一起的不同测试运行(来自不同的测试框架或并行执行)组织到同一个构建中。不同的测试系列由团队额外组织。系列名称和内部版本号/ID 以 . 分隔#

--series使用和--team选项的一些示例testarchiver

  • --series ${JENKINS_JOB_NAME}#${BUILD_NUMBER}
  • --series "UI tests"#<commit hash>
  • --series ${CURRENT_BRANCH}#${BUILD_ID} --team Team-A
  • --series manually_run

每个版本在系列中都有一个版本号。如果指定了内部版本号,则使用该编号。如果省略内部版本号/id,则内部版本号将从该系列中的前一个版本中检查并递增。如果内部版本号/id 不是数字,则将其视为内部版本标识符字符串。如果该 id 对系列来说是新的,则内部版本号会增加,就像没有指定内部版本号一样。如果在同一个测试系列中发现相同的构建 ID,则结果将添加到先前存档的相同构建下。

如果测试是在 CI 环境中执行的,则构建号/ID 是将存档结果链接到实际构建的绝佳方式。

系列也可以使用元数据来表示。任何带有名称前缀的元数据series都被解释为系列信息。这在使用侦听器时特别有用。例如,当使用 Robot Framework 元数据时--metadata team:A-Team --metadata series:JENKINS_JOB_NAME#BUILD_NUMBER

时间戳调整

一些测试框架在其时间戳中使用本地时间。对于存档到数据库,如果在不同时区查看和/或运行测试,这可能会出现问题。为了解决这个问题,提供了两种将时间调整回 GMT/UTC 的方法。

第一个允许用户以他们选择的秒为单位应用固定时间的调整。这对于已经运行测试并且运行它们的地点/时区已知的情况很有用。如果您在与运行测试不同的位置存档,此选项很有用。作为选项提供的时间值将添加到时间戳中。必须注意夏季时间不同的地方(通常 +1 小时)。

例如,如果测试在芬兰 (GMT+2) 运行,加上夏季 1 小时,则按分钟和秒计算总小时数并反转以调整正确方向,即 -(2+1) 60 60,所以 --time-夏令时adjust-secs -10800,否则-7200。

第二个提供基于系统时区和/或夏令时的自动调整(如果适用)。如果测试和归档在同一地点和时间执行,这将很有用。这假设如果使用多台计算机,它们的时区和夏令时设置是相同的。还必须注意不要在夏令时调整之前运行测试并在之后存档,因为时间将超过一小时。如果长时间运行的测试跨越时区调整边界,这很容易发生。这可以使用 --time-adjust-with-system-timezone 进行设置。

如果它的 adjust_with_system_timezone 参数设置为 True,则 ArchiverRobotListener 允许使用第二个选项。

为确保任何可选调整都可追溯,将两个元数据值添加到套件的测试运行中。如果 time-adjust-secs 设置为一个值,则具有该值的 time_adjust_secs 将写入 suite_metadata 表。如果--time-adjust-with-system-timezone包含选项,则添加 time-adjust-secs 和系统时区将作为 time_adjust_secs_total 写入 suite_metadata 表。

例如使用命令行

output_parser.py --time-adjust-secs -3600 --time-adjust-with-system-timezone ...

以下值将添加到 (GMT+2) 的 suite_metadata 表中

  • time_adjust_secs 值为 -3600
  • time_adjust_secs_total 为 -10800。

此示例模拟将夏令时(1hr = 3600 秒)添加到 7200 (GMT+2) 的系统偏移秒数。即,如果正在使用的计算机具有“夏令时”设置,并且您希望在归档期间手动添加它。

发行说明

  • 2.6.0 (2022-09-15)

    • --max_log_message_length控制归档日志消息长度的选项。默认为 2000 个字符。负值将从最后归档日志消息。
    • 忽略来自 Robot Framework 5.x 输入的没有警告的返回语句
  • 2.5.1 (2022-09-06)

    • JUnit 解析器更新以接受测试用例中缺少时间值的结果
    • XUnit 解析器更新以接受测试用例中缺少时间值的结果
  • 2.5.0 (2022-06-23)

    • 时间调整也会影响 test_run 的生成字段和所有项目的 start_time
    • 通过在失败时始终使用关键字来修复 pytest 解析器
    • 现在连接到数据库时使用端口选项
  • 2.4.0 (2021-04-28)

    • 支持归档 Robot Framework 4.0 的更新
    • 修复日志消息执行路径计算中的错误
  • 2.3.0 (2021-03-16)

    • 更好地支持为 ChangeEngine 提供更改和执行上下文
      • --changes用于馈送变化信息
      • --execution-id给定执行上下文的测试应用程序的标识符或版本。存储在 ChangeEngine 中并通过last_update查询返回。
  • 2.2.0 (2020-12-21)

    • 能够根据测试结果中的时间戳报告调整时间。
      • --time-adjust-secs允许手动调整给定值的时间戳
      • --time-adjust-with-system-timezone允许按时区和/或夏令时自动调整时间戳。
    • 支持解析 PHPUnit 输出
    • 变更引擎:
      • 侦听器忽略跳过的测试
      • 将测试类型添加到所有解析器
      • --execution-context用于设置结果的执行上下文的选项
    • 为了清楚起见,diff2change_context_list.py 现在使用术语更改上下文而不是简单的上下文
    • 为空数据库和包含项目测试生成的示例数据的数据库添加 Dockerfiles
  • 2.1.0 (2020-09-16)

    • 用于控制关键字和日志消息归档的新选项
      • --no-keywords用于忽略所有关键字数据
      • --no-keyword-stats用于不收集关键字统计数据
      • --ignore-logs不收集任何日志消息数据
      • --ignore-logs-below用于忽略给定日志级别以下的所有日志消息
  • 2.0.0 (2020-09-04)

    • 作为 pip 包分发pip3 install testarchiver并安装:
      • testarchiver脚本(又名:output_parser.py)
      • testarchive_schematool脚本(又名:database.py)
      • diff2change_context_list.py脚本
      • test_archiver模块
    • 管理模式更新的功能
      • TestArchiver 版本必须与架构版本匹配
      • TestArchiver 可以在明确允许时应用架构更新
      • 更新分为主要更新和次要更新
      • 次要更新向后兼容读取数据库的应用程序
      • 主要更新向后不兼容读取数据库的应用程序
    • 主要架构更新 #1:
      • 添加schema_updates用于记录架构更新的表
      • 向表中添加schema_version列以test_run使架构与旧版本 TestArchiver 不兼容
      • 为日志消息添加索引以提高查询性能
    • output_parser.py将cli 选项重命名--change_engine_url--change-engine-url
    • 记录测试用例、套件和日志消息的执行路径。
      • 该路径解释了项目在其测试运行中的位置。
      • 例如s1-s2-t3,表示顶层套件的第二个子套件中的第三个测试。
    • 次要架构更新 #2:
      • execution_path列添加到test_result,suite_resultlog_message
    • 为了清楚起见,重命名了 Robot Framework 侦听ArchiverListener.pyArchiverRobotListener.py
  • 1.2.0 (2020-08-18)

    • 使用 sqlite 数据库时重要的数据库完整性修复
    • 记录测试关键性(特定于机器人框架)
    • 重新设计配置管理
      • 允许统一使用配置文件和命令行参数
      • CLI 参数覆盖配置文件中设置的选项
  • 1.1.3 (2020-06-09)

    • 架构存在检查的性能修复
    • 改进的错误消息:
      • 尝试存档已存档的结果时出错
      • 找不到 psycopg2 模块时出错

项目详情


发布历史 发布通知| RSS订阅