1
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 1 year has passed since last update.

JUnit5の@BeforeEachと@AfterEachが実行されない

Last updated at Posted at 2022-07-06

問題

JUnit5でテスト実行時に@BeforeEachアノテーションと@AfterEachアノテーションのついたメソッドが実行されないことがあった。

解決策

下記リンクの回答で解決。

Your init() method is not invoked because you have not instructed Maven Surefire to use the JUnit Platform Surefire Provider.
Thus, surprisingly your test is not even being run with JUnit. Instead, it is being run with Maven Surefire's support for what they call POJO Tests.
Adding the following to your pom.xml should solve the problem.

<build>
   <plugins>
       <plugin>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.19.1</version>
           <dependencies>
               <dependency>
                   <groupId>org.junit.platform</groupId>
                   <artifactId>junit-platform-surefire-provider</artifactId>
                   <version>1.1.0</version>
               </dependency>
           </dependencies>
       </plugin>
   </plugins>
</build>

上記の設定をpom.xmlに追加すれば良い。

1
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
1
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?