You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于TestNG Extent Report中Tests与Steps差异的技术咨询

Understanding Tests vs Steps in TestNG Extent Reports

Hey there! Let’s clear up the confusion between Tests and Steps in Extent Reports using your exact scenario.

Core Difference Breakdown

1. What are "Tests" in Extent Reports?

Tests directly map to your TestNG @Test annotated methods. Each @Test method counts as one individual test case. So when you ran 2 test cases (one pass, one fail), the Tests section correctly shows 1 Pass, 1 Fail—this is tracking the overall result of each test method.

2. What are "Steps" in Extent Reports?

Steps are the granular, individual actions/validations you log within a test case. These are created using methods like test.log(Status.PASS/FAIL, "Step description") or extent.createNode("Step Name"). A single test case can have multiple steps, and each step has its own pass/fail status (though a failing step will usually cause the entire test to fail).

Why Your Stats Don’t Match

In your case, the failing test case likely contains 2 separate steps that both failed, while the passing test case has 1 successful step. That’s why Steps show 1 Pass, 2 Fail even though only one test case failed.

Example Code to Match Your Scenario

Here’s what your code might look like to produce this outcome:

import org.testng.Assert;
import org.testng.annotations.Test;
import com.aventstack.extentreports.Status;

@Test
public void demoTestPass() {
    // Create a test entry in Extent Report
    test = extent.createTest("demoTestPass", "This test will demonstrate the PASS test case");
    
    // Log a single passing step
    test.log(Status.PASS, "Successfully completed pre-condition and assertion");
    Assert.assertTrue(true); // Passing assertion
}

@Test
public void demoTestFail() {
    test = extent.createTest("demoTestFail", "This test will demonstrate the FAIL test case");
    
    // First failing step
    test.log(Status.FAIL, "Failed to validate first condition");
    Assert.assertTrue(false); // First failing assertion
    
    // Second failing step (might log as fail even if execution halts, depending on setup)
    test.log(Status.FAIL, "Could not proceed to second validation due to prior failure");
}

In this code:

  • demoTestPass is 1 Test with 1 Pass Step
  • demoTestFail is 1 Test with 2 Fail Steps

This exactly explains the stats you’re seeing: Tests (1 Pass, 1 Fail) vs Steps (1 Pass, 2 Fail).

Quick Recap

  • Tests: Track the overall result of each @Test method (test case level)
  • Steps: Track the result of individual actions/validations inside each test case (granular level)

内容的提问来源于stack exchange,提问作者Rabikatha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:40:10