Class TestReport

java.lang.Object
cloud.opencode.base.test.report.TestReport

public class TestReport extends Object
Test Report 测试报告

Collects and stores test results.

收集和存储测试结果。

Features | 主要功能:

  • Test result collection and reporting - 测试结果收集和报告
  • Multiple output formats - 多种输出格式

Usage Examples | 使用示例:

TestReport report = new TestReport("MySuite");
report.addPassed("test1", Duration.ofMillis(50));
report.complete();
System.out.println(report.getSummary());

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • TestReport

      public TestReport(String name)
      Create test report 创建测试报告
      Parameters:
      name - the report name | 报告名称
  • Method Details

    • add

      public void add(TestReport.TestResult result)
      Add test result 添加测试结果
      Parameters:
      result - the result | 结果
    • addPassed

      public void addPassed(String testName, Duration duration)
      Add passed test 添加通过的测试
      Parameters:
      testName - the test name | 测试名称
      duration - the duration | 时长
    • addFailed

      public void addFailed(String testName, Duration duration, Throwable error)
      Add failed test 添加失败的测试
      Parameters:
      testName - the test name | 测试名称
      duration - the duration | 时长
      error - the error | 错误
    • addSkipped

      public void addSkipped(String testName, String reason)
      Add skipped test 添加跳过的测试
      Parameters:
      testName - the test name | 测试名称
      reason - the reason | 原因
    • complete

      public void complete()
      Mark report as complete 标记报告为完成
    • getName

      public String getName()
      Get report name 获取报告名称
      Returns:
      the name | 名称
    • getResults

      public List<TestReport.TestResult> getResults()
      Get all results 获取所有结果
      Returns:
      the results | 结果
    • getTotalCount

      public int getTotalCount()
      Get total count 获取总数
      Returns:
      the count | 数量
    • getPassedCount

      public int getPassedCount()
      Get passed count 获取通过数
      Returns:
      the count | 数量
    • getFailedCount

      public int getFailedCount()
      Get failed count 获取失败数
      Returns:
      the count | 数量
    • getSkippedCount

      public int getSkippedCount()
      Get skipped count 获取跳过数
      Returns:
      the count | 数量
    • getTotalDuration

      public Duration getTotalDuration()
      Get total duration 获取总时长
      Returns:
      the duration | 时长
    • allPassed

      public boolean allPassed()
      Check if all tests passed 检查是否所有测试都通过
      Returns:
      true if all passed | 如果全部通过返回true
    • getSuccessRate

      public double getSuccessRate()
      Get success rate 获取成功率
      Returns:
      the success rate (0-1) | 成功率(0-1)
    • getSummary

      public String getSummary()
      Get summary 获取摘要
      Returns:
      the summary | 摘要
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • suiteName

      public String suiteName()
      Alias for getName()
    • timestamp

      public Instant timestamp()
      Alias for Instant.now()
    • totalTests

      public int totalTests()
      Alias for getTotalCount()
    • passedTests

      public int passedTests()
      Alias for getPassedCount()
    • failedTests

      public int failedTests()
      Alias for getFailedCount()
    • skippedTests

      public int skippedTests()
      Alias for getSkippedCount()
    • successRate

      public double successRate()
      Alias for getSuccessRate()
    • durationMs

      public long durationMs()
      Alias for getTotalDuration().toMillis()
    • testCases

      public List<TestReport.TestResult> testCases()
      Alias for getResults()