gpt4 book ai didi

junit - 如何自动从 JUnit 4 迁移到 JUnit 5?

转载 作者:行者123 更新时间:2023-12-04 23:38:42 32 4
gpt4 key购买 nike

本着this question from JUnit 3 to JUnit 4的精神, 是否有任何正则表达式列表到 有效地从 junit 4 API 迁移到 junit 5 API ,不管代码大小?

最佳答案

目前的工具不是很好,但正在改进:

  • IntelliJ:将大多数注释迁移到 JUnit 5 版本。但是,如果您的测试文件包含 @Rule,则不会执行任何操作。 s(例如, ExpectedException )自 v2018.2 起。
  • 容易出错:包含内置重构以自动迁移各种 JUnit 4 异常测试习惯用法(try/fail/catch/assert,ExpectedException s,@Test(expected = …))到 assertThrows ,完美地增强了 IntelliJ。

  • 我推荐以下步骤:
  • 将 JUnit 5 人工制品添加到您的测试依赖项中。
  • Install容易出错的编译器。
  • Configure它生成补丁迁移到 assertThrows ,启用以下检查(示例 Maven 配置如下):
  • TryFailRefactoring,
  • 预期异常重构,
  • 测试异常重构。
  • 使用内置的 IntelliJ refactorings迁移 JUnit 4
    JUnit 5 对应的注释和方法。

  • 我不知道有什么工具可以帮助自动迁移 ParameterizedExpectedException 之外的测试或规则.

    这是一个容易出错的配置示例:
    <build>
    <plugins>
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
    <compilerId>javac-with-errorprone</compilerId>
    <showWarnings>true</showWarnings>
    <forceJavacCompilerUse>true</forceJavacCompilerUse>
    <source>${java.compiler.source}</source>
    <target>${java.compiler.target}</target>
    <compilerArgs>
    <arg>-XepPatchChecks:TryFailRefactoring,ExpectedExceptionRefactoring,TestExceptionRefactoring</arg>
    <arg>-XepPatchLocation:${project.basedir}</arg>
    </compilerArgs>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>org.codehaus.plexus</groupId>
    <artifactId>plexus-compiler-javac-errorprone</artifactId>
    <version>2.8.3</version>
    </dependency>
    <dependency>
    <groupId>com.google.errorprone</groupId>
    <artifactId>error_prone_core</artifactId>
    <version>2.3.2</version>
    </dependency>
    </dependencies>
    </plugin>
    </plugins>
    </build>

    关于junit - 如何自动从 JUnit 4 迁移到 JUnit 5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46242083/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com