{"id":293803,"date":"2019-08-24T21:01:09","date_gmt":"2019-08-24T21:01:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=293803"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=293803","title":{"rendered":"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u0430 JUnit5 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e application.properties"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u044d\u0442\u0438\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f\u0445 \u2014 \u043a\u0430\u0436\u043e\u043c\u0443 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0418 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440, \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u0432\u2026 \u0444\u0430\u0439\u043b\u0435 <code>application.properties<\/code> \u2014 \u043a\u0430\u0436\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0443 \u0441\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c &#171;\u0432\u043a\u043b\/\u0432\u044b\u043a\u043b&#187;.<\/p>\n<p>  <\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442, \u0433\u0434\u0435 \u043c\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SpringBoot 2 \u0438 JUnit 5.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"predvaritelnye-nastroyki\">\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438<\/h1>\n<p>  <\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u043c JUnit 4, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 SpringBoot 2 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u043c <a href=\"https:\/\/junit.org\/junit5\/docs\/current\/user-guide\/#overview\">JUnit 5<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0435\u0441\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 <code>pom.xml<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;dependencies&gt;     &lt;!--...--&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;         &lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;         &lt;scope&gt;test&lt;\/scope&gt;         &lt;exclusions&gt;             &lt;exclusion&gt;                 &lt;groupId&gt;junit&lt;\/groupId&gt;                 &lt;artifactId&gt;junit&lt;\/artifactId&gt;             &lt;\/exclusion&gt;         &lt;\/exclusions&gt;     &lt;\/dependency&gt;     &lt;dependency&gt;         &lt;groupId&gt;org.junit.jupiter&lt;\/groupId&gt;         &lt;artifactId&gt;junit-jupiter-engine&lt;\/artifactId&gt;         &lt;version&gt;5.3.2&lt;\/version&gt;         &lt;scope&gt;test&lt;\/scope&gt;     &lt;\/dependency&gt;     &lt;!--...--&gt; &lt;\/dependencies&gt;<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"predpolagaemoe-reshenie\">\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 \u0441\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u043d\u0430 \u0442\u043e, \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043b\u0438 \u0442\u0435\u0441\u0442 \u0438\u043b\u0438 \u043d\u0435\u0442. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435 <code>application.properties<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"annotaciya\">\u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/master\/springboot2-junit5-skiptest\/src\/test\/java\/com\/bvn13\/example\/springboot\/junit\/skiptest\/TestEnabled.java\">\u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Retention(RetentionPolicy.RUNTIME) @ExtendWith(TestEnabledCondition.class) public @interface TestEnabled {     String property(); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"obrabotka-annotacii\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0411\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class TestEnabledCondition implements ExecutionCondition {      @Override     public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {         Optional&lt;TestEnabled&gt; annotation = context.getElement().map(e -&gt; e.getAnnotation(TestEnabled.class));          return context.getElement()                         .map(e -&gt; e.getAnnotation(TestEnabled.class))                         .map(annotation -&gt; {                             String property = annotation.property();                              return Optional.ofNullable(environment.getProperty(property, Boolean.class))                                     .map(value -&gt; {                                         if (Boolean.TRUE.equals(value)) {                                             return ConditionEvaluationResult.enabled(\"Enabled by property: \"+property);                                         } else {                                             return ConditionEvaluationResult.disabled(\"Disabled by property: \"+property);                                         }                                     }).orElse(                                             ConditionEvaluationResult.disabled(\"Disabled - property &lt;\"+property+\"&gt; not set!\")                                     );                         }).orElse(                                 ConditionEvaluationResult.enabled(\"Enabled by default\")                         );     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 (\u0431\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 Spring-\u0430 <code>@Component<\/code>), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>ExecutionCondition<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u2014 <code>ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context)<\/code>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e JUnit \u0442\u0435\u0441\u0442\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u2014 \u0434\u043e\u043b\u0436\u0435\u043d \u043b\u0438 \u0442\u0435\u0441\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0439 \u043f\u043e <a href=\"https:\/\/junit.org\/junit5\/docs\/current\/user-guide\/#extensions-conditions\">\u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 JUnit5<\/a> \u043c\u043e\u0436\u043d\u043e \u0432 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u043a\u0430\u043a \u043d\u0430\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 <code>application.properties<\/code> \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435?<\/p>\n<p>  <\/p>\n<h2 id=\"poluchenie-dostupa-k-kontekstu-spring-iz-konteksta-junit\">\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 Spring \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 JUnit<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 Spring, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0431\u044b\u043b \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043d\u0430\u0448 JUnit \u0442\u0435\u0441\u0442, \u0438\u0437 <code>ExtensionContext<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">Environment environment = SpringExtension.getApplicationContext(context).getEnvironment();<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/9a34719dbc7b616f0234e4dcd0d5376905aacc2e\/springboot2-junit5-skiptest\/src\/test\/java\/com\/bvn13\/example\/springboot\/junit\/skiptest\/TestEnabledCondition.java\">\u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 TestEnabledCondition<\/a>.<\/p>\n<p>  <\/p>\n<h1 id=\"sozdadim-testy\">\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0435\u0441\u0442\u044b<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@SpringBootTest public class SkiptestApplicationTests {      @TestEnabled(property = \"app.skip.test.first\")     @Test     public void testFirst() {         assertTrue(true);     }      @TestEnabled(property = \"app.skip.test.second\")     @Test     public void testSecond() {         assertTrue(false);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 <code>application.properties<\/code> \u0444\u0430\u0439\u043b \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">app.skip.test.first=true app.skip.test.second=false<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a&#8230;<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2af\/4f4\/130\/2af4f41307a1c6df08edf9583fdd084f.png\"><\/p>\n<p>  <\/p>\n<h1 id=\"sleduyuschiy-shag---otdelim-prefiksy-nashih-svoystv-v-annotaciyu-klassa\">\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u043e\u0442\u0434\u0435\u043b\u0438\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u044b \u043d\u0430\u0448\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430<\/h1>\n<p>  <\/p>\n<p>\u041f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043a\u0430\u0436\u0434\u044b\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u043f\u043e\u043b\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438\u0437 <code>application.properties<\/code> \u2014 \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u043e\u043d\u043d\u043e \u0438\u0445 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0435\u0441\u0442\u043e\u0432 \u2014 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c <a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/master\/springboot2-junit5-skiptest\/src\/test\/java\/com\/bvn13\/example\/springboot\/junit\/skiptest\/TestEnabledPrefix.java\">annotation<\/a> \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u0432 \u2014 <code>TestEnabledPrefix<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface TestEnabledPrefix {     String prefix(); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"obrabotka-i-ispolzovanie-annotacii-testenabledprefix\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 TestEnabledPrefix<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043d\u043e\u0432\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"davayte-sozdadim-vspomogatelnyy-klass-annotationdescription\">\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 AnnotationDescription<\/h3>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437 <code>application.properties<\/code> \u0438 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">public class TestEnabledCondition implements ExecutionCondition {      static class AnnotationDescription {         String name;         Boolean annotationEnabled;         AnnotationDescription(String prefix, String property) {             this.name = prefix + property;         }         String getName() {             return name;         }         AnnotationDescription setAnnotationEnabled(Boolean value) {             this.annotationEnabled = value;             return this;         }         Boolean isAnnotationEnabled() {             return annotationEnabled;         }     }      \/* ... *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f, \u0442.\u043a. \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c lambda-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"sozdadim-metod-kotoryy-izvlechet-nam-znachenie-svoystva-prefiks-iz-annotacii-klassa--testenabledprefix\">\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u0442 \u043d\u0430\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 &#171;\u043f\u0440\u0435\u0444\u0438\u043a\u0441&#187; \u0438\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 TestEnabledPrefix<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">public class TestEnabledCondition implements ExecutionCondition {      \/* ... *\/      private AnnotationDescription makeDescription(ExtensionContext context, String property) {         String prefix = context.getTestClass()                 .map(cl -&gt; cl.getAnnotation(TestEnabledPrefix.class))                 .map(TestEnabledPrefix::prefix)                 .map(pref -&gt; !pref.isEmpty() &amp;&amp; !pref.endsWith(\".\") ? pref + \".\" : \"\")                 .orElse(\"\");         return new AnnotationDescription(prefix, property);     }      \/* ... *\/  }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"i-teper-proverim-znachenie-svoystva-iz-applicationproperties-po-imeni-ukazannom-v-annotacii-testa\">\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437 <code>application.properties<\/code> \u043f\u043e \u0438\u043c\u0435\u043d\u0438, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0442\u0435\u0441\u0442\u0430<\/h3>\n<p>  <\/p>\n<pre><code class=\"java\">public class TestEnabledCondition implements ExecutionCondition {      \/* ... *\/      @Override     public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {         Environment environment = SpringExtension.getApplicationContext(context).getEnvironment();          return context.getElement()                 .map(e -&gt; e.getAnnotation(TestEnabled.class))                 .map(TestEnabled::property)                 .map(property -&gt; makeDescription(context, property))                 .map(description -&gt; description.setAnnotationEnabled(environment.getProperty(description.getName(), Boolean.class)))                 .map(description -&gt; {                     if (description.isAnnotationEnabled()) {                         return ConditionEvaluationResult.enabled(\"Enabled by property: \"+description.getName());                     } else {                         return ConditionEvaluationResult.disabled(\"Disabled by property: \"+description.getName());                     }                 }).orElse(                         ConditionEvaluationResult.enabled(\"Enabled by default\")                 );      }  }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/master\/springboot2-junit5-skiptest\/src\/test\/java\/com\/bvn13\/example\/springboot\/junit\/skiptest\/TestEnabledCondition.java\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430<\/a> \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"ispolzovanie-novoy-annotacii\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u043a <a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/master\/springboot2-junit5-skiptest\/src\/test\/java\/com\/bvn13\/example\/springboot\/junit\/skiptest\/SkiptestApplicationTests.java\">\u0442\u0435\u0441\u0442-\u043a\u043b\u0430\u0441\u0441\u0443<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">@SpringBootTest @TestEnabledPrefix(property = \"app.skip.test\") public class SkiptestApplicationTests {      @TestEnabled(property = \"first\")     @Test     public void testFirst() {         assertTrue(true);     }      @TestEnabled(property = \"second\")     @Test     public void testSecond() {         assertTrue(false);     }  }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u0442\u0430\u043b \u0447\u0438\u0449\u0435 \u0438 \u043f\u0440\u043e\u0449\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"hochu-vyrazit-blagodarnost-polzovatelyam-reddit-a-za-ih-sovety\">\u0425\u043e\u0447\u0443 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c reddit-\u0430 \u0437\u0430 \u0438\u0445 \u0441\u043e\u0432\u0435\u0442\u044b:<\/h2>\n<p>  <\/p>\n<p>1) <a href=\"https:\/\/www.reddit.com\/user\/dpash\/\">dpash<\/a> \u0437\u0430 <a href=\"https:\/\/www.reddit.com\/r\/java\/comments\/cuiqxf\/skip_junit_test_according_to_java_springframework\/exxz1yr?utm_source=share&amp;utm_medium=web2x\">\u0441\u043e\u0432\u0435\u0442<\/a><br \/>  2) <a href=\"https:\/\/www.reddit.com\/user\/BoyRobot777\/\">BoyRobot777<\/a> \u0437\u0430 <a href=\"https:\/\/www.reddit.com\/r\/java\/comments\/cuiqxf\/skip_junit_test_according_to_java_springframework\/exy8cnh?utm_source=share&amp;utm_medium=web2x\">\u0441\u043e\u0432\u0435\u0442<\/a><\/p>\n<p>  <\/p>\n<h4 id=\"ps\">P.S.<\/h4>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c. \u0410\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u0432 <a href=\"https:\/\/github.com\/bvn13\/JavaLessons\/blob\/master\/springboot2-junit5-skiptest\/README.md\">README.md<\/a> \u0444\u0430\u0439\u043b\u0435 \u0440\u044f\u0434\u043e\u043c \u0441 \u043a\u043e\u0434\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/464881\/\"> https:\/\/habr.com\/ru\/post\/464881\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u044d\u0442\u0438\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f\u0445 \u2014 \u043a\u0430\u0436\u043e\u043c\u0443 \u0441\u0432\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0418 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440, \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f, \u0432\u2026 \u0444\u0430\u0439\u043b\u0435 <code>application.properties<\/code> \u2014 \u043a\u0430\u0436\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u0443 \u0441\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u044c &#171;\u0432\u043a\u043b\/\u0432\u044b\u043a\u043b&#187;.<\/p>\n<p>  <\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u043d\u0435 \u043f\u0440\u0430\u0432\u0434\u0430 \u043b\u0438?<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442, \u0433\u0434\u0435 \u043c\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SpringBoot 2 \u0438 JUnit 5.<\/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-293803","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/293803","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=293803"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/293803\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}