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

配置junit5-system-exit扩展时遇到Agent未加载异常的问题求助

配置junit5-system-exit扩展时遇到Agent未加载异常的问题求助

我正在给一个会调用System.exit(1)来标识执行失败的命令行应用编写单元测试。因为我们使用的是Java 21,为了避开安全管理器相关的问题,我们打算采用junit5-system-exit扩展的解决方案。

按照该扩展GitHub仓库里的配置说明,我写的pom.xml内容如下:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
    <argLine/>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.11.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.ginsberg</groupId>
        <artifactId>junit5-system-exit</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>properties</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.5.2</version>
            <configuration>
                <argLine>@{argLine} -javaagent:${com.ginsberg:junit5-system-exit:jar}</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

可是当我执行测试的时候,却遇到了如下错误提示:

java.lang.IllegalStateException: SystemExitExtension Agent not loaded, please see documentation

看起来我没有正确配置Surefire插件,试了好几种调整方式都没解决问题,有没有大佬能帮我看看哪里出错了?

备注:内容来源于stack exchange,提问作者Bob Rivers

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 10:53:06