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

如何在IntelliJ中自动生成JUnit JSON格式测试报告?

How to Automatically Generate JSON Reports for Allure from JUnit in IntelliJ

Hey there! Let me walk you through setting up automatic JSON report generation for Allure when running JUnit tests in IntelliJ—this is totally doable once you leverage your build tool (Maven or Gradle) to handle the heavy lifting. Here's how to get it working:

For Maven Projects

  1. Update your pom.xml
    First, add the Allure JUnit dependency and Maven plugin to your project config. This tells Maven to generate the required JSON files during test execution automatically:

    <!-- Add to the dependencies section -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-junit4</artifactId>
        <version>2.24.0</version>
        <scope>test</scope>
    </dependency>
    
    <!-- Add to the build/plugins section -->
    <plugin>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-maven</artifactId>
        <version>2.12.0</version>
        <configuration>
            <reportVersion>2.24.0</reportVersion>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>report</goal>
                </goals>
                <phase>test</phase>
            </execution>
        </executions>
    </plugin>
    
  2. Configure your IntelliJ Run Setup

    • Open the Run/Debug Configurations dialog (click the dropdown next to the run button, then select "Edit Configurations").
    • Locate your existing JUnit configuration (or create a new one if needed).
    • Under the Before launch section, click the + button and select Run Maven Goal.
    • Set the goal to clean test—this triggers Maven to run tests and auto-generate JSON reports in the target/allure-results directory.
    • Save the configuration. Now every time you run this JUnit setup, the JSON files will be created automatically.

For Gradle Projects

  1. Update your build.gradle
    Add the Allure Gradle plugin and configure the test task to output JSON reports:

    plugins {
        id 'java'
        id 'io.qameta.allure' version '2.12.0'
    }
    
    dependencies {
        testImplementation 'io.qameta.allure:allure-junit4:2.24.0'
        testImplementation 'junit:junit:4.13.2'
    }
    
    test {
        useJUnit()
        systemProperty 'allure.results.directory', buildDir.path + '/allure-results'
    }
    
  2. Set Up the Run Configuration

    • Open Run/Debug Configurations and edit your JUnit config.
    • In Before launch, add a Run Gradle Task with the task clean test.
    • Save the config. Running tests via this setup will auto-generate JSON files in build/allure-results.

Verify It Works

After running your tests, check the respective directory (target/allure-results for Maven, build/allure-results for Gradle)—you’ll see .json files there. These are exactly what Allure needs to build its detailed report.

If you want to view the full Allure report right away, run the Maven goal allure:serve or Gradle task allureServe—this launches a local server with the interactive report.

内容的提问来源于stack exchange,提问作者j.barrio

相关产品推荐
方舟 Agent Plan

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

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