{"id":10357,"date":"2018-06-23T12:47:55","date_gmt":"2018-06-23T10:47:55","guid":{"rendered":"http:\/\/blog.wenzlaff.de\/?p=10357"},"modified":"2021-11-22T17:14:09","modified_gmt":"2021-11-22T16:14:09","slug":"wie-kann-eine-vaadin-spring-boot-anwendung-in-15-minuten-auf-junit-5-umgestellt-werden","status":"publish","type":"post","link":"http:\/\/blog.wenzlaff.de\/?p=10357","title":{"rendered":"Wie kann eine Vaadin Spring Boot Anwendung in 15 Minuten auf JUnit 5 umgestellt werden?"},"content":{"rendered":"<p>Wie kann eine Vaadin Spring Boot mit Hibernate Anwendung auf JUnit 5 f\u00fcr Eclipse Oxygene 3A umgestellt werden?<\/p>\n<p><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test.png\" alt=\"\" width=\"2732\" height=\"2048\" class=\"aligncenter size-full wp-image-8594\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test.png 2732w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test-300x225.png 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test-768x576.png 768w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2017\/07\/Junit-Test-1024x768.png 1024w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<p>1. Deaktivieren wir die JUnit (4.12) Libs in der pom.xml:<\/p>\n<pre class=\"lang:default decode:true \" >\t\r\n&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\r\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\r\n\t\t\t&lt;!-- Kein JUnit 4 mehr f\u00fcr den Test--&gt;\r\n\t\t\t&lt;exclusions&gt;\r\n\t\t\t\t&lt;exclusion&gt;\r\n\t\t\t\t\t&lt;groupId&gt;junit&lt;\/groupId&gt;\r\n\t\t\t\t\t&lt;artifactId&gt;junit&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;\/exclusion&gt;\r\n\t\t\t&lt;\/exclusions&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p>2. F\u00fcgen wir die n\u00f6tigen JUnit 5 Libs in der pom.xml hinzu:<\/p>\n<pre class=\"lang:default decode:true \" >\r\n&lt;!-- Alles f\u00fcr JUnit 5 --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.junit.jupiter&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;junit-jupiter-api&lt;\/artifactId&gt;\r\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;!-- and the engine for surefire and failsafe --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.junit.jupiter&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;junit-jupiter-engine&lt;\/artifactId&gt;\r\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p>3. Wir f\u00fcgen JUnit 5 dem Buildpfad hinzu:<\/p>\n<p><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.00.28.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.00.28.png\" alt=\"\" width=\"1023\" height=\"685\" class=\"aligncenter size-full wp-image-10359\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.00.28.png 1023w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.00.28-300x201.png 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.00.28-768x514.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a> Es sieht dann so aus:<br \/>\n<!--more--><br \/>\n<a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.25.39.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.25.39.png\" alt=\"\" width=\"697\" height=\"296\" class=\"aligncenter size-full wp-image-10361\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.25.39.png 697w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.25.39-300x127.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/a><\/p>\n<p>4. Wir erzeugen eine neue Testklasse, und achten darauf, das &#8222;New JUnit Jupiter test&#8220; markiert ist:<\/p>\n<p><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-11.51.49.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-11.51.49.png\" alt=\"\" width=\"524\" height=\"598\" class=\"aligncenter size-full wp-image-10363\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-11.51.49.png 524w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-11.51.49-263x300.png 263w\" sizes=\"auto, (max-width: 524px) 100vw, 524px\" \/><\/a><\/p>\n<p>Dann implementieren wir den Test, und achten darauf, das keine alten importe auf JUnit 4.x sondern immer die <strong>jupiter<\/strong> Imports vorhanden sind, z.B.<\/p>\n<pre class=\"lang:default decode:true \" >import static org.junit.Assert.assertEquals;\r\nimport static org.junit.Assert.assertNotNull;\r\n\r\nimport org.junit.jupiter.api.DisplayName;\r\nimport org.junit.jupiter.api.Test;\r\n\r\n\/**\r\n * Test des Zeilen Service mit JUnit 5.\r\n * \r\n * @author Thomas Wenzlaff\r\n *\r\n *\/\r\nclass ZeileServiceTest {\r\n\r\n\t@Test\r\n\t@DisplayName(\"Der Zeilen Service Test ini Test\")\r\n\tvoid testZeileService() {\r\n\r\n\t\tZeileService svr = new ZeileService(null, null, null);\r\n\t\tassertNotNull(svr);\r\n\r\n\t\tassertEquals(\"ZeileService\", svr.toString());\r\n\t}\r\n\r\n}<\/pre>\n<p>5. Und jetzt wird es interessant, schreiben wir einen Test mit DB Test und gestarteten Spring Boot, das geht mit nur zwei Annotationen <strong>@ExtendWith(SpringExtension.class)<\/strong><br \/>\nund <strong>@SpringBootTest<\/strong> mehr. Z.B.<\/p>\n<pre class=\"lang:default decode:true \" >\r\nimport static org.junit.Assert.assertEquals;\r\n\r\nimport java.util.List;\r\n\r\nimport org.junit.jupiter.api.DisplayName;\r\nimport org.junit.jupiter.api.Test;\r\nimport org.junit.jupiter.api.extension.ExtendWith;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.boot.test.context.SpringBootTest;\r\nimport org.springframework.test.context.junit.jupiter.SpringExtension;\r\n\r\nimport de.wenzlaff.krankenhaus.model.Arzt;\r\n\r\n\/**\r\n * Arzt Test mit DB und Repo.\r\n * \r\n * @author Thomas Wenzlaff\r\n *\r\n *\/\r\n@ExtendWith(SpringExtension.class)\r\n@SpringBootTest\r\nclass ArztRepositoryTest {\r\n\r\n\t@Autowired\r\n\tprivate ArztRepository arztRepository;\r\n\r\n\t@Test\r\n\t@DisplayName(\"Test mit Datenbank nach Name und Umlaute\")\r\n\tvoid testGetArztByName() {\r\n\t\tList&lt;Arzt&gt; aerzte = arztRepository.getArztByName(\"M\u00fcller\");\r\n\t\tassertEquals(1, aerzte.size());\r\n\t\tassertEquals(\"M\u00fcller\", aerzte.get(0).getName());\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>6. Test laufen lassen:<\/p>\n<p><a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.44.13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.44.13.png\" alt=\"\" width=\"442\" height=\"214\" class=\"aligncenter size-full wp-image-10365\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.44.13.png 442w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2018\/06\/Bildschirmfoto-2018-06-23-um-12.44.13-300x145.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie kann eine Vaadin Spring Boot mit Hibernate Anwendung auf JUnit 5 f\u00fcr Eclipse Oxygene 3A umgestellt werden? 1. Deaktivieren wir die JUnit (4.12) Libs in der pom.xml: &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;!&#8211; Kein JUnit 4 mehr f\u00fcr den Test&#8211;&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; 2. F\u00fcgen wir die n\u00f6tigen JUnit 5 Libs &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/blog.wenzlaff.de\/?p=10357\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eWie kann eine Vaadin Spring Boot Anwendung in 15 Minuten auf JUnit 5 umgestellt werden?\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220,5,3172,1361,2884,2953,79,3306,2658],"tags":[3217,3317,55,194,3299],"class_list":["post-10357","post","type-post","status-publish","format-standard","hentry","category-anleitung","category-java","category-java-10","category-java-8","category-java-9","category-junit-5","category-programmierung","category-spring","category-test-thema","tag-boot","tag-juint-5","tag-junit","tag-test-2","tag-vaadin"],"_links":{"self":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/10357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10357"}],"version-history":[{"count":0,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/10357\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}