英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论