如何从JUnit文件的testIT中提取编号并按测试结果分类写入文件?
JUnit测试结果分类脚本优化需求
需求说明
- 从JUnit文件中提取
testIT:后的数字编号 - 按以下规则分类写入文件:
- 若
testIT所在行的上一行包含/system-err或/failure,将编号写入失败文件 - 若
testIT所在行的上一行包含/system-out,将编号写入成功文件
- 若
示例展示
/system-err 失败场景
<system-err>Assertion Failure at Navigation.swift:88:Failed to get matching snapshot: No matches found for first query match sequence: `Descendants matching type NavigationBar`, given input App element pid: 21141 (no attribute values faulted in)</system-err> <system-out>testIT: C477997</system-out>
该场景下编号477997应写入失败文件。
/failure 失败场景
<failure message='Assertion Failure at Element.swift:277:Failed to get matching snapshot: No matches found for Elements matching predicate '"One" IN identifiers' from input {( Button, identifier: 'dictation', label: 'Диктовать', Disabled, Button, label: 'Почему мне не приходит СМС?', Button, label: 'Назад', Button, Button, label: 'Продолжить' )}'> </failure> <system-out>testIT: C478067</system-out>
该场景下编号478067应写入失败文件。
成功测试场景
<system-out> Setting up automation session</system-out> <system-out>testIT: C478057</system-out>
该场景下编号478057应写入成功文件。
预期输出
- 失败文件内容:
477997 478067
- 成功文件内容:
478057
当前脚本问题
使用以下脚本处理时:
xmllint $1 | awk -F'testIT: C|, | \(' '/testIT:/{print $2"\n"$4"\n"$6}'| awk 'NF!=0' | sort| uniq| 2>/dev/null > successfullCases.xml
输出结果带有多余的</system-out>标签,示例输出:
470836</system-out> 477975</system-out> 477997</system-out> 478057</system-out> 478067</system-out> 478098</system-out>
内容的提问来源于stack exchange,提问作者Yaroslav
相关产品推荐
相关产品推荐

