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

关于Allure报告合并含null/JSONObject.NULL参数测试用例的配置解决方法问询

Fixing Allure Report Merging of Null vs JSONObject.NULL Test Cases

Absolutely, you can resolve this merging issue—Allure groups these cases because its default parameter comparison logic treats null and JSONObject.NULL as identical. Here are three practical, actionable approaches to distinguish them:

1. Customize Test Case Names Directly

Allure uses test case names and parameters to group similar runs. By explicitly setting a unique name for each scenario, you force Allure to treat them as separate cases. Use Allure's lifecycle API to update the test name in your test method:

import io.qameta.allure.Allure;
import org.json.JSONObject;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class NullComparisonTests {

    @DataProvider(name = "nullVariants")
    public Object[][] provideNullVariants() {
        return new Object[][] {
            {null},
            {JSONObject.NULL}
        };
    }

    @Test(dataProvider = "nullVariants")
    public void testNullHandling(Object input) {
        // Set a distinct name based on the input type
        String testName = (input == null) ? "Test with Java Native Null" : "Test with JSONObject.NULL";
        Allure.getLifecycle().updateTestCase(testCase -> testCase.setName(testName));
        
        // Your test logic here
        // ...
    }
}

2. Explicitly Label Parameters for Allure

Instead of relying on Allure's default parameter rendering, add a custom parameter that clearly differentiates between the two null types. You can either pass a descriptive label alongside the parameter in your @DataProvider, or use Allure's parameter() method to manually set a distinct value:

@DataProvider(name = "labeledNullVariants")
public Object[][] provideLabeledNullVariants() {
    return new Object[][] {
        {null, "Java null"},
        {JSONObject.NULL, "JSONObject.NULL"}
    };
}

@Test(dataProvider = "labeledNullVariants")
public void testLabeledNullHandling(Object input, String nullTypeLabel) {
    // Add a custom parameter to Allure's report
    Allure.parameter("Null Type", nullTypeLabel);
    
    // Your test logic here
    // ...
}

This makes the parameter difference visible in the report and prevents merging, as Allure now recognizes unique parameter values for each test case.

3. Override Allure's Parameter Comparison Logic (Advanced)

If you need a global solution across all tests, you can customize how Allure compares parameters. This requires extending Allure's internal test result aggregation logic:

  • Create a custom implementation of TestResultAggregator that overrides the parameter matching logic.
  • Add a check to treat null and JSONObject.NULL as distinct values (e.g., by verifying their class type or using a custom equality check).
  • Register your custom aggregator in Allure's configuration.

Note: This approach is more complex and requires familiarity with Allure's internal APIs, so use it only if the simpler methods above don't meet your needs.

Bonus Check: Update Allure Version

First, confirm you're using the latest version of the Allure TestNG adapter. Some older versions had edge cases around null parameter handling, and upgrading might resolve the issue without writing custom code.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:19:35