0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Junitでthe temporary folder has not yet been created例外

Posted at

発生バージョン

  • Spring boot 2.4.2

トレースログ

java.lang.IllegalStateException: the temporary folder has not yet been created
    at org.junit.rules.TemporaryFolder.getRoot(TemporaryFolder.java:299)
    ...

原因のコード

@Rule
private TemporaryFolder tempFolder = new TemporaryFolder();

原因

@Rule, TemporaryFolderはJunit5で削除されていた。
JUnit3 -> 4みたいに破壊的な変更はないんだな~と思いながら書いてけど、そうでもなかったw

JUnit5での書き方

@TempDir
public Path tempFolder;

そもそも使わなくなった@RuleとTemporaryFolderがなんで@Deprecatedされてないんだと思い調べてみたところ、spring-boot-starter-testだけ依存してる場合は@Rule等が参照できずコンパイルエラーになりました。
少なくともspring-batch-testを依存関係に追加すると、使えもしないのにJunit4のモジュールが参照できてしまうようです。
使わないなら消しといたほうがよさそうです。

dependencies {
    ...

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
-   testImplementation 'org.springframework.batch:spring-batch-test'

    ...
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?