【发布时间】:2017-09-15 14:34:43
【问题描述】:
本着this question from JUnit 3 to JUnit 4 的精神,是否有任何正则表达式列表可以有效地从 junit 4 API 迁移到 junit 5 API,无论代码大小如何?
【问题讨论】:
-
无论如何您都无法迁移自定义规则..
本着this question from JUnit 3 to JUnit 4 的精神,是否有任何正则表达式列表可以有效地从 junit 4 API 迁移到 junit 5 API,无论代码大小如何?
【问题讨论】:
目前的工具不是很好,但正在改进:
@Rules(例如 ExpectedException),则不会执行任何操作。ExpectedExceptions、@Test(expected = …))迁移到assertThrows,完美增强了 IntelliJ。李>
我推荐以下步骤:
assertThrows,启用以下检查(示例 Maven 配置如下):
我不知道有任何工具可以帮助自动迁移Parameterized 测试或ExpectedException 以外的规则。
这是一个容易出错的配置示例:
<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>
【讨论】: