{"id":1939,"date":"2020-07-22T01:36:08","date_gmt":"2020-07-21T16:36:08","guid":{"rendered":"http:\/\/sparkling-software.club\/pekublog\/?p=1939"},"modified":"2020-07-22T01:39:00","modified_gmt":"2020-07-21T16:39:00","slug":"springboot%e3%81%ae%e3%83%86%e3%82%b9%e3%83%88%e3%82%92junit4%e3%81%8b%e3%82%89junit5%e3%81%ab%e7%a7%bb%e8%a1%8c%e3%81%99%e3%82%8b%e9%9a%9b%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9","status":"publish","type":"post","link":"http:\/\/sparkling-software.club\/pekublog\/?p=1939","title":{"rendered":"SpringBoot\u306e\u30c6\u30b9\u30c8\u3092JUnit4\u304b\u3089JUnit5\u306b\u79fb\u884c\u3059\u308b\u969b\u306e\u6ce8\u610f\u70b9"},"content":{"rendered":"<p>SpringBoot\u306e\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092JUnit4\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001JUnit5+AssertJ\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u79fb\u884c\u306e\u969b\u306b\u624b\u9593\u53d6\u3063\u305f\u7b87\u6240\u306b\u3064\u3044\u3066\u3001\u7d76\u5bfe\u306b\u5fd8\u308c\u308b\u306e\u3067\u5099\u5fd8\u3002<br \/>\n<strong><br \/>\n\uff08\uff11\uff09\u30e9\u30a4\u30d6\u30e9\u30ea<br \/>\n\uff08\uff12\uff09\u30c6\u30b9\u30c8\u30af\u30e9\u30b9<br \/>\n\uff08\uff13\uff09\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\uff08@Before\uff09<br \/>\n<\/strong><\/p>\n<p><strong>\uff08\uff11\uff09\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong><br \/>\n\u3000Maven\u306a\u3089pom.xml\u3001Gradle\u306a\u3089build.gradle\u306b\u8a18\u8ff0\u3059\u308b\u5185\u5bb9\u3067\u3059\u3002<br \/>\n\u3000JUnit4\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u6b8b\u3063\u3066\u3044\u308b\u3068\u3001\u540c\u540d\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\uff08@Test\uff09\u3092\u9593\u9055\u3063\u3066JUnit4\u306e\u65b9\u3067import\u3057\u3066\u3057\u307e\u3044\u3001\u3046\u307e\u304f\u30c6\u30b9\u30c8\u304c\u52d5\u304b\u306a\u3044\u3068\u3044\u3046\u30df\u30b9\u3092\u547c\u3073\u307e\u3059\u3002\uff13\u6642\u9593\u307b\u3069\u4f7f\u3063\u3066\u3057\u307e\u3063\u305f\u3002\u3002\u3002<\/p>\n<p>\u3000\u3068\u3044\u3046\u308f\u3051\u3067\u5bfe\u5fdc\u7b56\u3068\u3057\u3066\u3001\u3042\u3089\u304b\u3058\u3081JUnit4\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u6d88\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002spring-boot-starter-test\u304b\u3089junit\u3084junit-vintage\u3092\u9664\u5916\u3057\u307e\u3059\u3002<br \/>\n\u3000\u3000build.gradle\u306a\u3089\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n    testImplementation('org.springframework.boot:spring-boot-starter-test') {\r\n        exclude group: 'junit', module:'junit'\r\n        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'\r\n    }\r\n<\/pre>\n<p>\u3000JUnit5\u306f\u8907\u6570\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u69cb\u6210\u3055\u308c\u307e\u3059\u304c\u3001junit-vintage\u3092\u5165\u308c\u3066\u3057\u307e\u3046\u3068\u3084\u3063\u3071\u308aJUnit4\u7528\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u9593\u9055\u3063\u3066import\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u5fc5\u8981\u306a\u3051\u308c\u3070\u8a18\u8ff0\u3057\u306a\u3044\u65b9\u304c\u5b89\u5168\u304b\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u3002<br \/>\n\u3000\u3068\u308a\u3042\u3048\u305a\u4ee5\u4e0b\uff13\u70b9\u3092\u9069\u7528\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n    testImplementation 'org.junit.platform:junit-platform-surefire-provider:1.3.2'\r\n    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'\r\n    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'\r\n<\/pre>\n<p>\u3042\u3068\u306f\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u3001spring-security-test\u3084assertj-core\u306a\u3069\u3092\u8a18\u8ff0\u3002<\/p>\n<p><strong>\uff08\uff12\uff09\u30c6\u30b9\u30c8\u30af\u30e9\u30b9<\/strong><br \/>\n\u3000\u6b21\u306b\u30c6\u30b9\u30c8\u30af\u30e9\u30b9\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u304c\u3001\u6700\u4f4e\u9650\u4ee5\u4e0b\u306f\u5fc5\u8981\u304b\u3068\u601d\u3044\u307e\u3059\u3002MockMVC\u3067\u30c6\u30b9\u30c8\u3059\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n@ExtendWith(SpringExtension.class)\r\n@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)\r\n@AutoConfigureMockMvc\r\npublic class \u3007\u3007Test {\r\n<\/pre>\n<p>\u3053\u3053\u3067\u6ce8\u610f\u3057\u305f\u3044\u306e\u304c\u3001JUnit4\u74b0\u5883\u3067\u306f\u30c6\u30b9\u30c8\u30e9\u30f3\u30ca\u30fc\u3092\u300c@RunWith(SpringRunner.class)\u300d\u3068\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u300c@ExtendWith(SpringExtension.class)\u300d\u3068\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u70b9\u3067\u3059\u3002<\/p>\n<p>@SpringBootTest\u3068@AutoConfigureMockMvc\u306fJUnit4\u306e\u6642\u3068\u5909\u308f\u308a\u307e\u305b\u3093\u3002<\/p>\n<p><strong>\uff08\uff13\uff09\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\uff08@Before\uff09<\/strong><br \/>\n\u3000\u5404\u30c6\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u524d\u306b\u5b9f\u884c\u3057\u305f\u3044\u30e1\u30bd\u30c3\u30c9\uff08\u524d\u51e6\u7406\u306a\u3069\uff09\u306b\u306f\u300c@Before\u300d\u3092\u4ed8\u4e0e\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u3053\u308c\u304cJUnit5\u3067\u306f\u300c@BeforeEach\u300d\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3000\u3061\u306a\u307f\u306b@BeforeAll\u306fstatic\u30e1\u30bd\u30c3\u30c9\u306b\u306a\u308b\u306e\u3067\u3001static\u30d5\u30a3\u30fc\u30eb\u30c9\u306b@Autowired\u3067\u304d\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u79c1\u306fFlyway\u3067DB\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u884c\u3063\u3066\u304a\u308a\u3001DBSetUp\u3067DB\u30c6\u30b9\u30c8\u3092\u884c\u3063\u3066\u3044\u308b\u306e\u3067\u4ee5\u4e0b\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3082\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002GitHub\u306eflyway-test-extensions\u306eReadme\u306b\u4f7f\u7528\u65b9\u6cd5\u306a\u3069\u304c\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, FlywayTestExecutionListener.class })\r\n@FlywayTest\r\n@Transactional\r\n<\/pre>\n<p>\u3053\u3046\u3044\u3046\u306e\u3059\u3050\u5fd8\u308c\u308b\u304b\u3089\u66f8\u3044\u3066\u304a\u304b\u306a\u3044\u3068\u30fb\u30fb\u30fb\u3002<\/p>\n<fieldset style=\"border-style: solid; border-width: 1px;\">\n<legend><strong>\u5e83\u544a<\/strong><\/legend>\n<p><script src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\" async=\"\"><\/script><!-- \u30ec\u30af\u30bf\u30f3\u30b0\u30eb\u5e83\u544a --> <ins class=\"adsbygoogle\" style=\"display: inline-block; width: 336px; height: 280px;\" data-ad-client=\"ca-pub-0101691122871550\" data-ad-slot=\"7066468215\"><\/ins><script>\/\/ <![CDATA[\n(adsbygoogle = window.adsbygoogle || []).push({});\n\/\/ ]]><\/script><\/fieldset>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot\u306e\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092JUnit4\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001JUnit5+AssertJ\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002 \u79fb\u884c\u306e\u969b\u306b\u624b\u9593\u53d6\u3063\u305f\u7b87\u6240\u306b\u3064\u3044\u3066\u3001\u7d76\u5bfe\u306b\u5fd8\u308c\u308b\u306e\u3067\u5099\u5fd8\u3002 \uff08\uff11\uff09\u30e9\u30a4\u30d6\u30e9\u30ea \uff08\uff12\uff09\u30c6\u30b9\u30c8\u30af\u30e9\u30b9 \uff08\uff13 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,53],"tags":[],"_links":{"self":[{"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/posts\/1939"}],"collection":[{"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1939"}],"version-history":[{"count":4,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/posts\/1939\/revisions"}],"predecessor-version":[{"id":1944,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/posts\/1939\/revisions\/1944"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=\/wp\/v2\/media\/115"}],"wp:attachment":[{"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1939"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sparkling-software.club\/pekublog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}