{"id":66789,"date":"2017-06-14T01:00:06","date_gmt":"2017-06-13T22:00:06","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=66789"},"modified":"2017-06-13T18:21:58","modified_gmt":"2017-06-13T15:21:58","slug":"spring-boot-web-slice-test-sample","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html","title":{"rendered":"Spring Boot Web Slice test &#8211; Sample"},"content":{"rendered":"<p>Spring Boot\u00a0<a href=\"https:\/\/spring.io\/blog\/2016\/08\/30\/custom-test-slice-with-spring-boot-1-4\">introduced\u00a0<\/a><a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/html\/boot-features-testing.html#boot-features-testing-spring-boot-applications-testing-autoconfigured-tests\">test slicing <\/a> a while back and it has taken me some time to get my head around it and explore some of its nuances.<\/p>\n<h2>Background<\/h2>\n<p>The main reason to use this feature is to reduce the boilerplate. Consider a controller that looks like this, just for variety written using\u00a0<a href=\"https:\/\/kotlinlang.org\/\">Kotlin<\/a>.<\/p>\n<pre class=\"brush:java\">@RestController\r\n@RequestMapping(\"\/users\")\r\nclass UserController(\r\n        private val userRepository: UserRepository,\r\n        private val userResourceAssembler: UserResourceAssembler) {\r\n\r\n    @GetMapping\r\n    fun getUsers(pageable: Pageable, \r\n                 pagedResourcesAssembler: PagedResourcesAssembler&lt;User&gt;): PagedResources&lt;Resource&lt;User&gt;&gt; {\r\n        val users = userRepository.findAll(pageable)\r\n        return pagedResourcesAssembler.toResource(users, this.userResourceAssembler)\r\n    }\r\n\r\n    @GetMapping(\"\/{id}\")\r\n    fun getUser(id: Long): Resource&lt;User&gt; {\r\n        return Resource(userRepository.findOne(id))\r\n    }\r\n}<\/pre>\n<p>A traditional\u00a0<a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/htmlsingle\/#spring-mvc-test-server\">Spring Mock MVC test<\/a> to test this controller would be along these lines:<\/p>\n<pre class=\"brush:java\">@RunWith(SpringRunner::class)\r\n@WebAppConfiguration\r\n@ContextConfiguration\r\nclass UserControllerTests {\r\n\r\n    lateinit var mockMvc: MockMvc\r\n\r\n    @Autowired\r\n    private val wac: WebApplicationContext? = null\r\n\r\n    @Before\r\n    fun setup() {\r\n        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build()\r\n    }\r\n\r\n    @Test\r\n    fun testGetUsers() {\r\n        this.mockMvc.perform(get(\"\/users\")\r\n                .accept(MediaType.APPLICATION_JSON))\r\n                .andDo(print())\r\n                .andExpect(status().isOk)\r\n    }\r\n\r\n    @EnableSpringDataWebSupport\r\n    @EnableWebMvc\r\n    @Configuration\r\n    class SpringConfig {\r\n\r\n        @Bean\r\n        fun userController(): UserController {\r\n            return UserController(userRepository(), UserResourceAssembler())\r\n        }\r\n\r\n        @Bean\r\n        fun userRepository(): UserRepository {\r\n            val userRepository = Mockito.mock(UserRepository::class.java)\r\n            given(userRepository.findAll(Matchers.any(Pageable::class.java)))\r\n                    .willAnswer({ invocation -&gt;\r\n                        val pageable = invocation.arguments[0] as Pageable\r\n                        PageImpl(\r\n                                listOf(\r\n                                        User(id = 1, fullName = \"one\", password = \"one\", email = \"one@one.com\"),\r\n                                        User(id = 2, fullName = \"two\", password = \"two\", email = \"two@two.com\"))\r\n                                , pageable, 10)\r\n                    })\r\n            return userRepository\r\n        }\r\n    }\r\n}<\/pre>\n<p>There is a lot of ceremony involved in setting up such a test &#8211; a web application context which understands a web environment is pulled in, a configuration which sets up the Spring MVC environment needs to be created and MockMvc which is handle to the testing framework needs to be set-up before each test.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2>Web Slice Test<\/h2>\n<p>A web slice test when compared to the previous test is far simpler and focuses on testing the controller and hides a lot of the boilerplate code:<\/p>\n<pre class=\"brush:java\">@RunWith(SpringRunner::class)\r\n@WebMvcTest(UserController::class)\r\nclass UserControllerSliceTests {\r\n\r\n    @Autowired\r\n    lateinit var mockMvc: MockMvc\r\n\r\n    @MockBean\r\n    lateinit var userRepository: UserRepository\r\n\r\n    @SpyBean\r\n    lateinit var userResourceAssembler: UserResourceAssembler\r\n\r\n    @Test\r\n    fun testGetUsers() {\r\n\r\n        this.mockMvc.perform(get(\"\/users\").param(\"page\", \"0\").param(\"size\", \"1\")\r\n                .accept(MediaType.APPLICATION_JSON))\r\n                .andDo(print())\r\n                .andExpect(status().isOk)\r\n    }\r\n\r\n    @Before\r\n    fun setUp(): Unit {\r\n        given(userRepository.findAll(Matchers.any(Pageable::class.java)))\r\n                .willAnswer({ invocation -&gt;\r\n                    val pageable = invocation.arguments[0] as Pageable\r\n                    PageImpl(\r\n                            listOf(\r\n                                    User(id = 1, fullName = \"one\", password = \"one\", email = \"one@one.com\"),\r\n                                    User(id = 2, fullName = \"two\", password = \"two\", email = \"two@two.com\"))\r\n                            , pageable, 10)\r\n                })\r\n    }\r\n}<\/pre>\n<p>It works by creating a Spring Application context but filtering out anything that is not relevant to the web layer and loading up only the controller which has been passed into the @WebTest annotation. Any dependency that the controller requires can be injected in as a mock.<\/p>\n<p>Coming to some of the nuances, say if I wanted to inject one of the fields myself the way to do it is have the test use a custom Spring Configuration, for a test this is done by using a inner static class annotated with @TestConfiguration the following way:<\/p>\n<pre class=\"brush:java\">@RunWith(SpringRunner::class)\r\n@WebMvcTest(UserController::class)\r\nclass UserControllerSliceTests {\r\n\r\n    @Autowired\r\n    lateinit var mockMvc: MockMvc\r\n\r\n    @Autowired\r\n    lateinit var userRepository: UserRepository\r\n\r\n    @Autowired\r\n    lateinit var userResourceAssembler: UserResourceAssembler\r\n\r\n    @Test\r\n    fun testGetUsers() {\r\n\r\n        this.mockMvc.perform(get(\"\/users\").param(\"page\", \"0\").param(\"size\", \"1\")\r\n                .accept(MediaType.APPLICATION_JSON))\r\n                .andDo(print())\r\n                .andExpect(status().isOk)\r\n    }\r\n\r\n    @Before\r\n    fun setUp(): Unit {\r\n        given(userRepository.findAll(Matchers.any(Pageable::class.java)))\r\n                .willAnswer({ invocation -&gt;\r\n                    val pageable = invocation.arguments[0] as Pageable\r\n                    PageImpl(\r\n                            listOf(\r\n                                    User(id = 1, fullName = \"one\", password = \"one\", email = \"one@one.com\"),\r\n                                    User(id = 2, fullName = \"two\", password = \"two\", email = \"two@two.com\"))\r\n                            , pageable, 10)\r\n                })\r\n    }\r\n\r\n    @TestConfiguration\r\n    class SpringConfig {\r\n\r\n        @Bean\r\n        fun userResourceAssembler(): UserResourceAssembler {\r\n            return UserResourceAssembler()\r\n        }\r\n\r\n        @Bean\r\n        fun userRepository(): UserRepository {\r\n            return mock(UserRepository::class.java)\r\n        }\r\n    }\r\n\r\n}<\/pre>\n<p>The beans from the &#8220;TestConfiguration&#8221; adds on to the configuration which the Slice tests depend on and don&#8217;t completely replace it.<\/p>\n<p>On the other hand, if I wanted to override the loading of the main &#8220;@SpringBootApplication&#8221; annotated class then I can pass in a Spring Configuration class explicitly, but the catch is that I have to now take care of all of loading up the relevant Spring Boot features myself (enabling auto-configuration, appropriate scanning etc), so a way around it to explicitly annotate the configuration as a Spring Boot Application the following way:<\/p>\n<pre class=\"brush:java\">@RunWith(SpringRunner::class)\r\n@WebMvcTest(UserController::class)\r\nclass UserControllerExplicitConfigTests {\r\n\r\n    @Autowired\r\n    lateinit var mockMvc: MockMvc\r\n\r\n    @Autowired\r\n    lateinit var userRepository: UserRepository\r\n\r\n    @Test\r\n    fun testGetUsers() {\r\n\r\n        this.mockMvc.perform(get(\"\/users\").param(\"page\", \"0\").param(\"size\", \"1\")\r\n                .accept(MediaType.APPLICATION_JSON))\r\n                .andDo(print())\r\n                .andExpect(status().isOk)\r\n    }\r\n\r\n    @Before\r\n    fun setUp(): Unit {\r\n        given(userRepository.findAll(Matchers.any(Pageable::class.java)))\r\n                .willAnswer({ invocation -&gt;\r\n                    val pageable = invocation.arguments[0] as Pageable\r\n                    PageImpl(\r\n                            listOf(\r\n                                    User(id = 1, fullName = \"one\", password = \"one\", email = \"one@one.com\"),\r\n                                    User(id = 2, fullName = \"two\", password = \"two\", email = \"two@two.com\"))\r\n                            , pageable, 10)\r\n                })\r\n    }\r\n\r\n    @SpringBootApplication(scanBasePackageClasses = arrayOf(UserController::class))\r\n    @EnableSpringDataWebSupport\r\n    class SpringConfig {\r\n\r\n        @Bean\r\n        fun userResourceAssembler(): UserResourceAssembler {\r\n            return UserResourceAssembler()\r\n        }\r\n\r\n        @Bean\r\n        fun userRepository(): UserRepository {\r\n            return mock(UserRepository::class.java)\r\n        }\r\n    }\r\n\r\n}<\/pre>\n<p>The catch though is that now other tests may end up finding this inner configuration which is far from ideal!, so my learning has been to depend on bare minimum slice testing, and if needed extend it using @TestConfiguration.<\/p>\n<p>I have a little more detailed code sample available at\u00a0<a href=\"https:\/\/github.com\/bijukunjummen\/blog-boot-project\">my github repo<\/a> which has working examples to play with.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/www.java-allandsundry.com\/2017\/06\/spring-boot-web-slice-test-sample.html\">Spring Boot Web Slice test &#8211; Sample<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/join-us\/jcg\/\">JCG partner<\/a> Biju Kunjummen at the <a href=\"http:\/\/www.java-allandsundry.com\/\">all and sundry<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The main reason to use this feature is to reduce the boilerplate. Consider a controller that looks like this, just for variety written using\u00a0Kotlin. @RestController @RequestMapping(&#8220;\/users&#8221;) class UserController( private &hellip;<\/p>\n","protected":false},"author":236,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[854],"class_list":["post-66789","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Boot Web Slice test - Sample - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot Web Slice test - Sample - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-13T22:00:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Biju Kunjummen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Biju Kunjummen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html\"},\"author\":{\"name\":\"Biju Kunjummen\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\"},\"headline\":\"Spring Boot Web Slice test &#8211; Sample\",\"datePublished\":\"2017-06-13T22:00:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html\"},\"wordCount\":429,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Spring Boot\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html\",\"name\":\"Spring Boot Web Slice test - Sample - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2017-06-13T22:00:06+00:00\",\"description\":\"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/06\\\/spring-boot-web-slice-test-sample.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Boot Web Slice test &#8211; Sample\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\",\"name\":\"Biju Kunjummen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"caption\":\"Biju Kunjummen\"},\"sameAs\":[\"http:\\\/\\\/biju-allandsundry.blogspot.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Biju-Kunjummen\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot Web Slice test - Sample - Java Code Geeks","description":"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html","og_locale":"en_US","og_type":"article","og_title":"Spring Boot Web Slice test - Sample - Java Code Geeks","og_description":"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The","og_url":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-06-13T22:00:06+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Biju Kunjummen","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Biju Kunjummen","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html"},"author":{"name":"Biju Kunjummen","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5"},"headline":"Spring Boot Web Slice test &#8211; Sample","datePublished":"2017-06-13T22:00:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html"},"wordCount":429,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Spring Boot"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html","url":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html","name":"Spring Boot Web Slice test - Sample - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2017-06-13T22:00:06+00:00","description":"Spring Boot\u00a0introduced\u00a0test slicing a while back and it has taken me some time to get my head around it and explore some of its nuances. Background The","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2017\/06\/spring-boot-web-slice-test-sample.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Boot Web Slice test &#8211; Sample"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5","name":"Biju Kunjummen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","caption":"Biju Kunjummen"},"sameAs":["http:\/\/biju-allandsundry.blogspot.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/Biju-Kunjummen"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/66789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=66789"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/66789\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=66789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=66789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=66789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}