如何阻止 jacocoTestReport 在测试通过时记录日志?

huangapple go评论91阅读模式
英文:

How to stop jacocoTestReport from logging when a test is passed?

问题

我目前在GitHub Action中运行jacocoTestReport以生成测试报告。目前,每个通过的测试都会在日志中记录为ClassName > MethodName(MethodArguments) PASSED的结构,其中ClassName是测试类的名称,MethodName是测试方法的名称,MethodArguments是测试方法的参数。

随着项目的增长和测试的添加,GitHub Action的输出开始包含大量这些日志,这使得在测试不通过时很难找到失败的测试。

是否有一种方法可以阻止记录这些日志消息,并仅输出测试失败的消息?

英文:

I currently run jacocoTestReport as apart of a GitHub Action to generate a test report. At the moment every test that passes has a line logged in the structure of ClassName > MethodName(MethodArguments) PASSED where ClassName is the name of the test class, MethodName is the name of the test method and MethodArguments are arguments that the test method takes.

As the project has grown and tests have been added, the output for the GitHub Action is starting to contain a lot of these logs which makes it difficult to find the failing tests when a test doesn't pass.

Is there a way to prevent these log messages being logged and only output messages for tests which fail?

答案1

得分: 1

我最终将此分解为几个步骤:

- name: 运行 Jacoco 测试报告
  run: |
        ./gradlew jacocoTestReport --warning-mode=none | grep --color=always -e '^' -e 'FAILED' |& tee ./full_test_report.txt
- name: 仅显示失败的测试
  run: |
        grep -vE '(^ *$|PASSED|^> Task|Starting a Gradle Daemon|actionable tasks:)' ./full_test_report.txt

我保留了现有的 "运行 Jacoco 测试报告" 步骤,以便保留完整的测试输出。在这一步中,我添加了一个 grep 命令来突出显示失败的测试,并添加了一个 tee 命令来将控制台输出输出到 ./full_test_report.txt

接下来,我添加了 "仅显示失败的测试" 步骤,它会从此输出文件中删除一些不需要的正则表达式。

英文:

I ended up breaking this down into a few steps:

- name: Run Jacoco Test Report
  run: |
        ./gradlew jacocoTestReport --warning-mode=none | grep --color=always -e '^' -e 'FAILED' |& tee ./full_test_report.txt
- name: Failed tests only
  run: |
        grep -vE '(^ *$|PASSED|^> Task|Starting a Gradle Daemon|actionable tasks:)' ./full_test_report.txt

I kept the existing "Run Jacoco Test Report" step so that full test output was retained. In this step, I added a grep command to highlight failed tests and a tee command to output the console output to ./full_test_report.txt.

Next, I added the "Failed tests only" step which grepped this output file removing a few unwanted regular expressions.

huangapple
  • 本文由 发表于 2023年5月25日 10:26:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定