{"id":402683,"date":"2024-06-29T16:39:49","date_gmt":"2024-06-29T16:39:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=402683"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=402683","title":{"rendered":"<span>\u0422\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e JUnit 5 &#8212;\u00a0\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u00a0@AfterEach<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<blockquote>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043f\u043e JUnit 5. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/590607\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u00a0<em>@AfterEach<\/em>\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u00a0\u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e<strong> <\/strong><code>@Test, @RepeatedTest, @ParameterizedTest, <\/code>\u0438\u043b\u0438<code>\u00a0@TestFactory<\/code><strong> <\/strong>\u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u00a0JUnit 5\u00a0@AfterEach\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\u00a0<code>@After<\/code> \u0432 JUnit 4.<\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e \u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434.<\/p>\n<h3>1. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @AfterEach<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@AfterEach<\/code> \u043a \u043c\u0435\u0442\u043e\u0434\u0443,\u00a0\u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"java\">@AfterEach public void cleanUpEach(){     \/\/Test cleanup code }  @Test void succeedingTest() {     \/\/test code and assertions }<\/code><\/pre>\n<p>\u0410\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434\u00a0\u041d\u0415 \u0414\u041e\u041b\u0416\u0415\u041d \u0431\u044b\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c<strong>,<\/strong>\u00a0\u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"java\">@AfterEach public static void cleanUpEach(){     \/\/Test cleanup code }  \/\/Error  org.junit.platform.commons.JUnitException: @AfterEach method 'public static void com.howtodoinjava.junit5.examples.JUnit5AnnotationsExample.cleanUpEach()' must not be static.<\/code><\/pre>\n<blockquote>\n<p><strong>@AfterEach \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u0445<\/strong><\/p>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach,<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432) \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u043d\u0435 <em>\u0441\u043a\u0440\u044b\u0442\u044b<\/em> \u0438\u043b\u0438 \u043d\u0435 <em>\u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b<\/em>.\u00a0<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u00a0\u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445.<code>@AfterEach<\/code><strong>\u00a0<\/strong><code>@AfterEach.<\/code><\/p>\n<\/blockquote>\n<h3>2. \u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @AfterEach<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440.\u00a0\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Calculator<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u00a0<code>add<\/code>.<\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0435\u0441\u0442 5 \u0440\u0430\u0437 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@RepeatedTest<\/code>.\u00a0\u042d\u0442\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u00a0<code>add<\/code> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d 5 \u0440\u0430\u0437.<\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00a0<code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<pre><code class=\"java\">import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.RepetitionInfo; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo;  public class AfterAnnotationsTest {      @DisplayName(\"Add operation test\")     @RepeatedTest(5)     void addNumber(TestInfo testInfo, RepetitionInfo repetitionInfo)     {         System.out.println(\"Running test -&amp;gt; \" + repetitionInfo.getCurrentRepetition());         Assertions.assertEquals(2, Calculator.add(1, 1), \"1 + 1 should equal 2\");     }      @AfterAll     public static void cleanUp(){         System.out.println(\"After All cleanUp() method called\");     }      @AfterEach     public void cleanUpEach(){         System.out.println(\"After Each cleanUpEach() method called\");     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"java\">package com.howtodoinjava.junit5.examples;  public class Calculator {     public int add(int a, int b) {         return a + b;     } }<\/code><\/pre>\n<pre><code class=\"bash\">Running test -> 1 After Each cleanUpEach() method called  Running test -> 2 After Each cleanUpEach() method called  Running test -> 3 After Each cleanUpEach() method called  Running test -> 4 After Each cleanUpEach() method called  Running test -> 5 After Each cleanUpEach() method called  After All cleanUp() method called<\/code><\/pre>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00a0<code>@AfterEach<\/code>\u00a0\u043c\u0435\u0442\u043e\u0434 <code>cleanUpEach()<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0\u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f!!!<\/p>\n<blockquote>\n<p><a href=\"https:\/\/github.com\/lokeshgupta1981\/Junit5Examples\/tree\/master\/JUnit5Examples\" rel=\"noopener noreferrer nofollow\">\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/590757\/\"> https:\/\/habr.com\/ru\/articles\/590757\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<blockquote>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0430 \u043f\u043e JUnit 5. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/590607\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u00a0<em>@AfterEach<\/em>\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u00a0\u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u043e\u0433\u043e<strong> <\/strong><code>@Test, @RepeatedTest, @ParameterizedTest, <\/code>\u0438\u043b\u0438<code>\u00a0@TestFactory<\/code><strong> <\/strong>\u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435.<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u00a0JUnit 5\u00a0@AfterEach\u00a0\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\u00a0<code>@After<\/code> \u0432 JUnit 4.<\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e \u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434.<\/p>\n<h3>1. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @AfterEach<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@AfterEach<\/code> \u043a \u043c\u0435\u0442\u043e\u0434\u0443,\u00a0\u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"java\">@AfterEach public void cleanUpEach(){     \/\/Test cleanup code }  @Test void succeedingTest() {     \/\/test code and assertions }<\/code><\/pre>\n<p>\u0410\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434\u00a0\u041d\u0415 \u0414\u041e\u041b\u0416\u0415\u041d \u0431\u044b\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c<strong>,<\/strong>\u00a0\u0438\u043d\u0430\u0447\u0435 \u043e\u043d \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"java\">@AfterEach public static void cleanUpEach(){     \/\/Test cleanup code }  \/\/Error  org.junit.platform.commons.JUnitException: @AfterEach method 'public static void com.howtodoinjava.junit5.examples.JUnit5AnnotationsExample.cleanUpEach()' must not be static.<\/code><\/pre>\n<blockquote>\n<p><strong>@AfterEach \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u0445<\/strong><\/p>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>@AfterEach,<\/code> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432) \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u043d\u0435 <em>\u0441\u043a\u0440\u044b\u0442\u044b<\/em> \u0438\u043b\u0438 \u043d\u0435 <em>\u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b<\/em>.\u00a0<\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u00a0\u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445.<code>@AfterEach<\/code><strong>\u00a0<\/strong><code>@AfterEach.<\/code><\/p>\n<\/blockquote>\n<h3>2. \u041f\u0440\u0438\u043c\u0435\u0440 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @AfterEach<\/h3>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440.\u00a0\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u00a0<code>Calculator<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u00a0<code>add<\/code>.<\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0435\u0441\u0442 5 \u0440\u0430\u0437 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@RepeatedTest<\/code>.\u00a0\u042d\u0442\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0435\u0441\u0442\u00a0<code>add<\/code> \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d 5 \u0440\u0430\u0437.<\/p>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00a0<code>@AfterEach<\/code> \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<pre><code class=\"java\">import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.RepetitionInfo; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo;  public class AfterAnnotationsTest {      @DisplayName(\"Add operation test\")     @RepeatedTest(5)     void addNumber(TestInfo testInfo, RepetitionInfo repetitionInfo)     {         System.out.println(\"Running test -&amp;gt; \" + repetitionInfo.getCurrentRepetition());         Assertions.assertEquals(2, Calculator.add(1, 1), \"1 + 1 should equal 2\");     }      @AfterAll     public static void cleanUp(){         System.out.println(\"After All cleanUp() method called\");     }      @AfterEach     public void cleanUpEach(){         System.out.println(\"After Each cleanUpEach() method called\");     } }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"java\">package com.howtodoinjava.junit5.examples;  public class Calculator {     public int add(int a, int b) {         return a + b;     } }<\/code><\/pre>\n<pre><code class=\"bash\">Running test -> 1 After Each cleanUpEach() method called  Running test -> 2 After Each cleanUpEach() method called  Running test -> 3 After Each cleanUpEach() method called  Running test -> 4 After Each cleanUpEach() method called  Running test -> 5 After Each cleanUpEach() method called  After All cleanUp() method called<\/code><\/pre>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439\u00a0<code>@AfterEach<\/code>\u00a0\u043c\u0435\u0442\u043e\u0434 <code>cleanUpEach()<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0\u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f!!!<\/p>\n<blockquote>\n<p><a href=\"https:\/\/github.com\/lokeshgupta1981\/Junit5Examples\/tree\/master\/JUnit5Examples\" rel=\"noopener noreferrer nofollow\">\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/590757\/\"> https:\/\/habr.com\/ru\/articles\/590757\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-402683","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402683"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402683\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}