{"id":406731,"date":"2024-06-29T19:06:33","date_gmt":"2024-06-29T19:06:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=406731"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=406731","title":{"rendered":"<span>\u0422\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e JUnit 5 &#8212;\u00a0\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b JUnit 5 \u0442\u0435\u0441\u0442\u0430<\/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 <a href=\"https:\/\/habr.com\/ru\/post\/590607\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<p>\u0412 JUnit 5 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0442\u0435\u0441\u0442\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438, \u0442\u043e \u0435\u0441\u0442\u044c @BeforeAll, @BeforeEach, @AfterEach \u0438 @AfterAll. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>@Test<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 org.junit.jupiter.api.<\/p>\n<p><strong>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/strong> <\/p>\n<ol>\n<li>\n<p>\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 Before \u0438 After <\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>Assertions<\/p>\n<\/li>\n<li>\n<p>Assumptions<\/p>\n<\/li>\n<\/ol>\n<h3>1. \u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/h3>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. JUnit \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0442\u0440\u0438 \u0444\u0430\u0437\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439.<\/p>\n<ol>\n<li>\n<p><strong>Setup<\/strong> (\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430): \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. JUnit \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <em>\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043b\u0430\u0441\u0441\u0430<\/em> (@BeforeAll) \u0438 <em>\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0435\u0442\u043e\u0434\u0430<\/em> (@BeforeEach). \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0442\u044f\u0436\u0435\u043b\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043b\u0435\u0433\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>Test Execution <\/strong>(\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430): \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430 \u0438 <em>assertion<\/em>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0443\u0441\u043f\u0435\u0445 \u0438\u043b\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0443 \u0442\u0435\u0441\u0442\u0430. <\/p>\n<\/li>\n<li>\n<p><strong>Cleanup <\/strong>(\u043e\u0447\u0438\u0441\u0442\u043a\u0430): \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u043f\u0435. \u041a\u0430\u043a \u043d\u0430 \u044d\u0442\u0430\u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043e\u0447\u0438\u0441\u0442\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <em>\u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/em> (@AfterAll) \u0438 <em>\u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u0435\u0442\u043e\u0434\u0430<\/em> (@AfterEach).<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/8ab\/b44\/91a\/8abb4491a78b734e93b7c122206e07ca.jpeg\" alt=\"\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430\" title=\"\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430\" width=\"961\" height=\"382\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8ab\/b44\/91a\/8abb4491a78b734e93b7c122206e07ca.jpeg\" data-blurred=\"true\"\/><figcaption>\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/figcaption><\/figure>\n<h3>2. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 Before \u0438 After <\/h3>\n<p>\u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0432 <em>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0442\u0435\u0441\u0442\u0430<\/em> \u043d\u0430\u043c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0440\u0435\u0434\u044b \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u044b.<\/p>\n<ul>\n<li>\n<p>\u0412 JUnit \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @BeforeAll \u0438 @AfterAll &#8212; \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e &#8212; \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430 \u0432\u0435\u0441\u044c \u0446\u0438\u043a\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b <code>static<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>@BeforeEach<\/code> \u0438\u00a0<code>@AfterEach<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0435\u0441\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c\u00a0<code>static<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u00a0<code>@BeforeAll<\/code>), \u0442\u043e \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"java\">public class AppTest {      @BeforeAll     static void setup(){         System.out.println(\"@BeforeAll executed\");     }      @BeforeEach     void setupThis(){         System.out.println(\"@BeforeEach executed\");     }      @Test     void testCalcOne()     {         System.out.println(\"======TEST ONE EXECUTED=======\");         Assertions.assertEquals( 4 , Calculator.add(2, 2));     }      @Test     void testCalcTwo()    {         System.out.println(\"======TEST TWO EXECUTED=======\");         Assertions.assertEquals( 6 , Calculator.add(2, 4));     }      @AfterEach     void tearThis(){         System.out.println(\"@AfterEach executed\");     }      @AfterAll     static void tear(){         System.out.println(\"@AfterAll executed\");     } }<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">@BeforeAll executed  @BeforeEach executed ======TEST ONE EXECUTED======= @AfterEach executed  @BeforeEach executed ======TEST TWO EXECUTED======= @AfterEach executed  @AfterAll executed<\/code><\/pre>\n<h3>3. \u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0435\u0441\u0442 \u0432 JUnit 5, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Disabled. \u042d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\u00a0<code>@Ignored<\/code>\u00a0JUnit 4.<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Disabled<\/code>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435) \u0438\u043b\u0438 \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code>@Disabled @Test void testCalcTwo() {     System.out.println(\"======TEST TWO EXECUTED=======\");     Assertions.assertEquals( 6 , Calculator.add(2, 4)); }<\/code><\/pre>\n<h3>4. Assertions<\/h3>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u0440\u043e\u0448\u0435\u043b \u043e\u043d \u0438\u043b\u0438 \u043d\u0435\u0442.\u00a0\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/howtodoinjava.com\/junit-5\/junit-5-assertions-examples\" rel=\"noopener noreferrer nofollow\">Assertions\u00a0<\/a>(\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439).<\/p>\n<p>\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0435\u0441\u0442\u0430.\u00a0\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u0441\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f JUnit Jupiter \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0435\u00a0<a href=\"https:\/\/junit.org\/junit5\/docs\/current\/api\/org.junit.jupiter.api\/org\/junit\/jupiter\/api\/Assertions.html\" rel=\"noopener noreferrer nofollow\">org.junit.jupiter.Assertions<\/a>.<\/p>\n<pre><code class=\"java\">@Test public void test()  {     \/\/Test will pass     Assertions.assertEquals(4, Calculator.add(2, 2));            \/\/Test will fail      Assertions.assertEquals(3, Calculator.add(2, 2), \"Calculator.add(2, 2) test failed\");            \/\/Test will fail      Supplier&lt;String> messageSupplier  = ()-> \"Calculator.add(2, 2) test failed\";     Assertions.assertEquals(3, Calculator.add(2, 2), messageSupplier); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u00a0<code>Assertions.fail()<\/code>.<\/p>\n<pre><code>@Test void testCase() {      Assertions.fail(\"not found good reason to pass\"); }<\/code><\/pre>\n<h3>5. Assumptions<\/h3>\n<p><a href=\"https:\/\/junit.org\/junit5\/docs\/current\/api\/org.junit.jupiter.api\/org\/junit\/jupiter\/api\/Assumptions.html\" rel=\"noopener noreferrer nofollow\">Assumptions<\/a> (\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f)\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u00a0<code>static<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439.\u00a0\u041d\u0435\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.\u00a0\u0412 \u043e\u0442\u0447\u0435\u0442\u0435 \u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p><code>assumeFalse():<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e\u00a0\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <em>false<\/em>.<\/p>\n<\/li>\n<li>\n<p><code>assumeTrue()<\/code>: \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435,\u00a0\u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c\u00a0<em>true<\/em>.<\/p>\n<\/li>\n<li>\n<p><code>assumingThat()<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>Executable<\/code>, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">@Test void testOnDev() {     System.setProperty(\"ENV\", \"DEV\");     Assumptions.assumeTrue(\"DEV\".equals(System.getProperty(\"ENV\")));     \/\/remainder of test will proceed }  @Test void testOnProd() {     System.setProperty(\"ENV\", \"PROD\");     Assumptions.assumeTrue(\"DEV\".equals(System.getProperty(\"ENV\")));     \/\/remainder of test will be aborted }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f\u00a0<strong>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 JUnit \u0442\u0435\u0441\u0442\u0430<\/strong>.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f!!!<\/p>\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<\/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\/590699\/\"> https:\/\/habr.com\/ru\/articles\/590699\/<\/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 <a href=\"https:\/\/habr.com\/ru\/post\/590607\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<p>\u0412 JUnit 5 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0442\u0435\u0441\u0442\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438, \u0442\u043e \u0435\u0441\u0442\u044c @BeforeAll, @BeforeEach, @AfterEach \u0438 @AfterAll. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0435\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 <code>@Test<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 org.junit.jupiter.api.<\/p>\n<p><strong>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/strong> <\/p>\n<ol>\n<li>\n<p>\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 Before \u0438 After <\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>Assertions<\/p>\n<\/li>\n<li>\n<p>Assumptions<\/p>\n<\/li>\n<\/ol>\n<h3>1. \u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/h3>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. JUnit \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u0442\u0440\u0438 \u0444\u0430\u0437\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439.<\/p>\n<ol>\n<li>\n<p><strong>Setup<\/strong> (\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430): \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430. JUnit \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 <em>\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043b\u0430\u0441\u0441\u0430<\/em> (@BeforeAll) \u0438 <em>\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0435\u0442\u043e\u0434\u0430<\/em> (@BeforeEach). \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0442\u044f\u0436\u0435\u043b\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0443\u0440\u043e\u0432\u043d\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043b\u0435\u0433\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0443\u0440\u043e\u0432\u043d\u044f \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>Test Execution <\/strong>(\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430): \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430 \u0438 <em>assertion<\/em>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0443\u0441\u043f\u0435\u0445 \u0438\u043b\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0443 \u0442\u0435\u0441\u0442\u0430. <\/p>\n<\/li>\n<li>\n<p><strong>Cleanup <\/strong>(\u043e\u0447\u0438\u0441\u0442\u043a\u0430): \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u0442\u0430\u043f\u0435. \u041a\u0430\u043a \u043d\u0430 \u044d\u0442\u0430\u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438, \u043e\u0447\u0438\u0441\u0442\u043a\u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f <em>\u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430<\/em> (@AfterAll) \u0438 <em>\u0443\u0440\u043e\u0432\u043d\u0435 \u043c\u0435\u0442\u043e\u0434\u0430<\/em> (@AfterEach).<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption>\u0424\u0430\u0437\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0442\u0435\u0441\u0442\u0430<\/figcaption><\/figure>\n<h3>2. \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 Before \u0438 After <\/h3>\n<p>\u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0432 <em>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0442\u0435\u0441\u0442\u0430<\/em> \u043d\u0430\u043c \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0441\u0440\u0435\u0434\u044b \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u044b.<\/p>\n<ul>\n<li>\n<p>\u0412 JUnit \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @BeforeAll \u0438 @AfterAll &#8212; \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e &#8212; \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430 \u0432\u0435\u0441\u044c \u0446\u0438\u043a\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b <code>static<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>@BeforeEach<\/code> \u0438\u00a0<code>@AfterEach<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0435\u0441\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c\u00a0<code>static<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u00a0<code>@BeforeAll<\/code>), \u0442\u043e \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"java\">public class AppTest {      @BeforeAll     static void setup(){         System.out.println(\"@BeforeAll executed\");     }      @BeforeEach     void setupThis(){         System.out.println(\"@BeforeEach executed\");     }      @Test     void testCalcOne()     {         System.out.println(\"======TEST ONE EXECUTED=======\");         Assertions.assertEquals( 4 , Calculator.add(2, 2));     }      @Test     void testCalcTwo()    {         System.out.println(\"======TEST TWO EXECUTED=======\");         Assertions.assertEquals( 6 , Calculator.add(2, 4));     }      @AfterEach     void tearThis(){         System.out.println(\"@AfterEach executed\");     }      @AfterAll     static void tear(){         System.out.println(\"@AfterAll executed\");     } }<\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">@BeforeAll executed  @BeforeEach executed ======TEST ONE EXECUTED======= @AfterEach executed  @BeforeEach executed ======TEST TWO EXECUTED======= @AfterEach executed  @AfterAll executed<\/code><\/pre>\n<h3>3. \u041e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0435\u0441\u0442 \u0432 JUnit 5, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @Disabled. \u042d\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\u00a0<code>@Ignored<\/code>\u00a0JUnit 4.<\/p>\n<p>\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Disabled<\/code>\u00a0\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u043a \u043a\u043b\u0430\u0441\u0441\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435) \u0438\u043b\u0438 \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code>@Disabled @Test void testCalcTwo() {     System.out.println(\"======TEST TWO EXECUTED=======\");     Assertions.assertEquals( 6 , Calculator.add(2, 4)); }<\/code><\/pre>\n<h3>4. Assertions<\/h3>\n<p>\u0412 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043f\u0440\u043e\u0448\u0435\u043b \u043e\u043d \u0438\u043b\u0438 \u043d\u0435\u0442.\u00a0\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/howtodoinjava.com\/junit-5\/junit-5-assertions-examples\" rel=\"noopener noreferrer nofollow\">Assertions\u00a0<\/a>(\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0439).<\/p>\n<p>\u0423\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0442\u0435\u0441\u0442\u0430.\u00a0\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0432\u0441\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f JUnit Jupiter \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0432\u00a0\u043a\u043b\u0430\u0441\u0441\u0435\u00a0<a href=\"https:\/\/junit.org\/junit5\/docs\/current\/api\/org.junit.jupiter.api\/org\/junit\/jupiter\/api\/Assertions.html\" rel=\"noopener noreferrer nofollow\">org.junit.jupiter.Assertions<\/a>.<\/p>\n<pre><code class=\"java\">@Test public void test()  {     \/\/Test will pass     Assertions.assertEquals(4, Calculator.add(2, 2));            \/\/Test will fail      Assertions.assertEquals(3, Calculator.add(2, 2), \"Calculator.add(2, 2) test failed\");            \/\/Test will fail      Supplier&lt;String> messageSupplier  = ()-> \"Calculator.add(2, 2) test failed\";     Assertions.assertEquals(3, Calculator.add(2, 2), messageSupplier); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442 \u043d\u0435 \u043f\u0440\u043e\u0448\u0435\u043b, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434\u00a0<code>Assertions.fail()<\/code>.<\/p>\n<pre><code>@Test void testCase() {      Assertions.fail(\"not found good reason to pass\"); }<\/code><\/pre>\n<h3>5. Assumptions<\/h3>\n<p><a href=\"https:\/\/junit.org\/junit5\/docs\/current\/api\/org.junit.jupiter.api\/org\/junit\/jupiter\/api\/Assumptions.html\" rel=\"noopener noreferrer nofollow\">Assumptions<\/a> (\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f)\u00a0\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u00a0<code>static<\/code> \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439.\u00a0\u041d\u0435\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044e \u0442\u0435\u0441\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.\u00a0\u0412 \u043e\u0442\u0447\u0435\u0442\u0435 \u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438\u043c\u0435\u0435\u0442 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p><code>assumeFalse():<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e\u00a0\u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <em>false<\/em>.<\/p>\n<\/li>\n<li>\n<p><code>assumeTrue()<\/code>: \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435,\u00a0\u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c\u00a0<em>true<\/em>.<\/p>\n<\/li>\n<li>\n<p><code>assumingThat()<\/code>: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>Executable<\/code>, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">@Test void testOnDev() {     System.setProperty(\"ENV\", \"DEV\");     Assumptions.assumeTrue(\"DEV\".equals(System.getProperty(\"ENV\")));     \/\/remainder of test will proceed }  @Test void testOnProd() {     System.setProperty(\"ENV\", \"PROD\");     Assumptions.assumeTrue(\"DEV\".equals(System.getProperty(\"ENV\")));     \/\/remainder of test will be aborted }<\/code><\/pre>\n<p>\u0412\u044b\u0448\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f\u00a0<strong>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 JUnit \u0442\u0435\u0441\u0442\u0430<\/strong>.<\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f!!!<\/p>\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<\/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\/590699\/\"> https:\/\/habr.com\/ru\/articles\/590699\/<\/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-406731","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/406731","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=406731"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/406731\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=406731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=406731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=406731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}