{"id":288338,"date":"2018-08-22T05:10:02","date_gmt":"2018-08-22T01:10:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288338"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2018-08-22T01:10:02","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288338","title":{"rendered":"\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0443\u0447\u0435\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Topjava \u043d\u0430 JUnit 5 \u0437\u0430 10 \u043c\u0438\u043d. \u0418\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Extensions"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420891\/\" class=\"post__text post__text-html js-mediator-article\">\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<\/p>\n<p>  \u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0430\u0436\u0438\u0440\u043e\u0432\u043a\u0435 Spring 5\/JPA Enterprise (Topjava) \u043d\u0430\u0448 \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441 JUnit 4 \u043d\u0430 JUnit 5.2. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430. \u0425\u043e\u0447\u0443 \u043a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043d\u0438\u0445 \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 JUnit 5 Extensions \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0432 10 \u043c\u0438\u043d\u0443\u0442\u043d\u043e\u043c \u0432\u0438\u0434\u0435\u043e.<\/p>\n<div class=\"oembed\">\n<div>\n<div style=\"left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.2493%;\"><iframe src=\"https:\/\/www.youtube.com\/embed\/YmLzT-j1hU4?rel=0&amp;showinfo=1&amp;hl=en-US\" style=\"border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;\" allowfullscreen scrolling=\"no\"><\/iframe><\/div>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import org.junit.jupiter.api.extension.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StopWatch;  public class TimingExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, AfterAllCallback {      private static final Logger log = LoggerFactory.getLogger(\"result\");      private StopWatch stopWatch;      @Override     public void beforeAll(ExtensionContext ctx) {         stopWatch = new StopWatch(\"Execution time of \" + ctx.getRequiredTestClass().getSimpleName());     }      @Override     public void beforeTestExecution(ExtensionContext ctx) {         log.info(\"Start stopWatch\");         stopWatch.start(ctx.getDisplayName());     }      @Override     public void afterTestExecution(ExtensionContext ctx) {         stopWatch.stop();         log.info(\"stop stopWatch\");     }      @Override     public void afterAll(ExtensionContext ctx) {         log.info('\\n' + stopWatch.prettyPrint() + '\\n');     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438:<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/junit.org\/junit5\">JUnit 5 homepage<\/a><\/li>\n<li><a href=\"https:\/\/junit.org\/junit5\/docs\/snapshot\/user-guide\/#overview\">Overview<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/post\/337700\">10 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0439<\/a><\/li>\n<li><a href=\"https:\/\/junit.org\/junit5\/docs\/current\/user-guide\/#extensions\">Extension Model<\/a><\/li>\n<li><a href=\"http:\/\/www.baeldung.com\/junit-5\">A Guide to JUnit 5<\/a><\/li>\n<li><a href=\"http:\/\/www.baeldung.com\/junit-5-migration\">Migrating from JUnit 4<\/a><\/li>\n<li><a href=\"https:\/\/junit.org\/junit5\/docs\/snapshot\/user-guide\/#extensions-lifecycle-callbacks-before-after-execution\">Before and After Test Execution Callbacks<\/a><\/li>\n<li><a href=\"https:\/\/junit.org\/junit5\/docs\/snapshot\/user-guide\/#writing-tests-conditional-execution\">Conditional Test Execution<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/junit-team\/junit5\/wiki\/Third-party-Extensions\">Third party Extensions<\/a><\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/43280250\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f assertThat<\/a><\/li>\n<\/ul>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! <br \/>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f JUnit 4 \u0438 \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430 JUnit 5, \u044d\u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0432\u0438\u0434\u0435\u043e \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u0442 \u0432\u0430\u0441. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 JUnit 5 \u0432 \u0412\u0430\u0448\u0438\u0445 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/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\/post\/420891\/\"> https:\/\/habr.com\/post\/420891\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420891\/\" class=\"post__text post__text-html js-mediator-article\">\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<\/p>\n<p>  \u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0430\u0436\u0438\u0440\u043e\u0432\u043a\u0435 Spring 5\/JPA Enterprise (Topjava) \u043d\u0430\u0448 \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441 JUnit 4 \u043d\u0430 JUnit 5.2. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0435\u043d, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u044e\u0430\u043d\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430. \u0425\u043e\u0447\u0443 \u043a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043d\u0438\u0445 \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 JUnit 5 Extensions \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0432 10 \u043c\u0438\u043d\u0443\u0442\u043d\u043e\u043c \u0432\u0438\u0434\u0435\u043e.<\/p>\n<div class=\"oembed\">\n<div>\n<div style=\"left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.2493%;\"><iframe src=\"https:\/\/www.youtube.com\/embed\/YmLzT-j1hU4?rel=0&amp;showinfo=1&amp;hl=en-US\" style=\"border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;\" allowfullscreen scrolling=\"no\"><\/iframe><\/div>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0442\u0435\u0441\u0442\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">import org.junit.jupiter.api.extension.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StopWatch;  public class TimingExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, AfterAllCallback {      private static final Logger log = LoggerFactory.getLogger(\"result\");      private StopWatch stopWatch;      @Override     public void beforeAll(ExtensionContext ctx) {         stopWatch = new StopWatch(\"Execution time of \" + ctx.getRequiredTestClass().getSimpleName());     }      @Override     public void beforeTestExecution(ExtensionContext ctx) {         log.info(\"Start stopWatch\");         stopWatch.start(ctx.getDisplayName());     }      @Override     public void afterTestExecution(ExtensionContext ctx) {         stopWatch.stop();         log.info(\"stop stopWatch\");     }      @Override     public void afterAll(ExtensionContext ctx) {         log.info('\\n' + stopWatch.prettyPrint() + '\\n');     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/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-288338","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288338","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=288338"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288338\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}