{"id":98209,"date":"2019-09-15T15:15:01","date_gmt":"2019-09-15T12:15:01","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=98209"},"modified":"2019-09-12T14:03:25","modified_gmt":"2019-09-12T11:03:25","slug":"efficient-enterprise-testing-unit-use-case","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html","title":{"rendered":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6)"},"content":{"rendered":"<p>In the first part of the series we saw some generally applicable principles and constraints that effective tests should fulfill. In this part, we will have a closer look at code-level unit tests and <em>component<\/em> or <em>use case<\/em> tests.<\/p>\n<p><strong>Unit tests<\/strong><\/p>\n<p>Unit tests verify the behavior of a single unit, usually a class, while all concerns that are external to the unit are ignored or simulated. Unit tests should test the business logic of the individual units, without verifying further integration or configuration thereof.<\/p>\n<p>From my experience, most enterprise developers have a pretty good understanding, how unit tests are constructed. You can have a look at this example in my <a href=\"https:\/\/github.com\/sdaschner\/coffee-testing\/tree\/master\/coffee-shop\/src\/test\/java\" target=\"_blank\" rel=\"noopener noreferrer\">coffee-testing project<\/a> to get an idea. Most projects are using JUnit in combination with Mockito to mock dependencies, and ideally AssertJ to effectively define readable assertions. What I always pick upon is that we can execute the unit tests without special extensions or runners, i.e. running them with plain JUnit only. The reason for that is simple: execution time; we should be able to run hundreds of tests within a few milliseconds.<\/p>\n<p>Unit tests generally perform very fast and they easily support crafting complex test suites or special development workflows, since they\u2019re easy to execute and don\u2019t impose constraints on the test suite life cycle.<\/p>\n<p>However, one shortcoming of having many unit tests that mock the dependencies of the tested class is that they will be tightly coupled to the implementation, especially the class structures and methods, which make it hard to refactor our code. In other words, for every refactoring action in the production code, the test code needs to change as well. In the worst case, this leads developers to do less refactorings, simply because they become too cumbersome, which quickly results in declining quality of the project\u2019s code. Ideally, developers should be able to refactor code and move things around, as long as they don\u2019t alter the behavior of the application, as it is perceived from it\u2019s users. Unit tests don\u2019t always make it easy to refactor production code.<\/p>\n<p>From experience in projects, unit tests are very effective in testing code that has a high density of concise logic or functionality, like the implementation of a specific algorithm, and at the same time doesn\u2019t interact too much with other components. The less dense or complex the code in a specific class, the lower the cyclomatic complexity, or the higher the interaction with other components, the less effective unit tests are in testing that class. Especially in microservices with a comparable small amount of specialized business logic and a high amount of integration to external systems, there\u2019s arguably less need for having many unit tests. The individual units of these systems usually contain little specialized logic, apart from a few exceptions. This needs to be taken into account when choosing the trade-off where to spend our time and effort on.<\/p>\n<p><strong><em>Use case<\/em> tests<\/strong><\/p>\n<p>In order to tackle the issue of tightly coupling the tests to the implementation, we can use a slightly different approach to widen the scope of tests. In <a href=\"https:\/\/blog.sebastian-daschner.com\/entries\/book-modern-java-ee\" target=\"_blank\" rel=\"noopener noreferrer\">my book<\/a>, I described the concepts of <em>component tests<\/em>, for lack of a better term, which we might also call <em>use case<\/em> tests.<\/p>\n<p>Use case tests are code-level integration tests that don\u2019t make use of embedded containers nor reflection scanning, just yet, for reasons of test startup time. They verify the business logic behavior of coherent components that usually participate in a single use case, from the business method of the <em>boundary<\/em> down to all involved components. Integration to external systems such as databases are mocked away.<\/p>\n<p>Building up such scenarios without using a more advanced technology that automatically wires up the components sounds like a lot of effort. However, we define reusable test components, or <em>test doubles<\/em>, that extend the components with mocking, wiring, and test configuration, in order to minimize the overall effort of refactoring changes. The goal is to craft single responsibilities that limit the impact of change to a single or few classes in the test scope. Doing this in a reusable way limits the overall required effort and pays off once the project grows larger, since we only pay the plumbing costs once per component, which amortizes quickly.<\/p>\n<p>To get a better idea, imagine we\u2019re testing the use case of ordering a coffee, which includes two classes, <code>CoffeeShop<\/code>, and <code>OrderProcessor<\/code>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"720\" height=\"311\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/testing-use-case-tests.png\" alt=\"\" class=\"wp-image-98222\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/testing-use-case-tests.png 720w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/testing-use-case-tests-300x130.png 300w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/figure>\n<\/div>\n<p>The test double classes <code>CoffeeShopTestDouble<\/code> and <code>OrderProcessorTestDouble<\/code>, or <code>*TD<\/code>, reside in the test scope of the project while they\u2019re extending the <code>CoffeeShop<\/code> and <code>OrderProcessor<\/code> components which reside in the main scope. The test doubles may setup the required mocking and wiring logic and potentially extend the public interface of the class with use case-related mocking or verification methods.<\/p>\n<p>The following shows the test double class for the <code>CoffeeShop<\/code> component:<\/p>\n<div>\n<div id=\"highlighter_555652\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">class<\/code> <code class=\"java plain\">CoffeeShopTestDouble <\/code><code class=\"java keyword\">extends<\/code> <code class=\"java plain\">CoffeeShop {<\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code> <code class=\"java plain\">CoffeeShopTestDouble(OrderProcessorTestDouble orderProcessorTestDouble) {<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">entityManager = mock(EntityManager.<\/code><code class=\"java keyword\">class<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">orderProcessor = orderProcessorTestDouble;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number7 index6 alt2\">&nbsp;<\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">void<\/code> <code class=\"java plain\">verifyCreateOrder(Order order) {<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">verify(entityManager).merge(order);<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number11 index10 alt2\">&nbsp;<\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">void<\/code> <code class=\"java plain\">verifyProcessUnfinishedOrders() {<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">verify(entityManager).createNamedQuery(Order.FIND_UNFINISHED, Order.<\/code><code class=\"java keyword\">class<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number15 index14 alt2\">&nbsp;<\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">void<\/code> <code class=\"java plain\">answerForUnfinishedOrders(List&lt;Order&gt; orders) {<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java comments\">\/\/ setup entity manager mock behavior<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>The test double class can access the fields and constructors of the <code>CoffeeShop<\/code> base class to setup the dependencies. It uses other components in their test double form, for example <code>OrderProcessorTestDouble<\/code>, to be able to invoke additional mocking or verification methods that are part of the use case.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The test double classes are reusable components that are written once per project scope and are used in multiple <em>use case<\/em> tests:<\/p>\n<div>\n<div id=\"highlighter_120120\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<div class=\"line number21 index20 alt2\">21<\/div>\n<div class=\"line number22 index21 alt1\">22<\/div>\n<div class=\"line number23 index22 alt2\">23<\/div>\n<div class=\"line number24 index23 alt1\">24<\/div>\n<div class=\"line number25 index24 alt2\">25<\/div>\n<div class=\"line number26 index25 alt1\">26<\/div>\n<div class=\"line number27 index26 alt2\">27<\/div>\n<div class=\"line number28 index27 alt1\">28<\/div>\n<div class=\"line number29 index28 alt2\">29<\/div>\n<div class=\"line number30 index29 alt1\">30<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">class<\/code> <code class=\"java plain\">CoffeeShopTest {<\/code><\/div>\n<div class=\"line number2 index1 alt1\">&nbsp;<\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">private<\/code> <code class=\"java plain\">CoffeeShopTestDouble coffeeShop;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">private<\/code> <code class=\"java plain\">OrderProcessorTestDouble orderProcessor;<\/code><\/div>\n<div class=\"line number5 index4 alt2\">&nbsp;<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java color1\">@BeforeEach<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">void<\/code> <code class=\"java plain\">setUp() {<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">orderProcessor = <\/code><code class=\"java keyword\">new<\/code> <code class=\"java plain\">OrderProcessorTestDouble();<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop = <\/code><code class=\"java keyword\">new<\/code> <code class=\"java plain\">CoffeeShopTestDouble(orderProcessor);<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number11 index10 alt2\">&nbsp;<\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java color1\">@Test<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">void<\/code> <code class=\"java plain\">testCreateOrder() {<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">Order order = <\/code><code class=\"java keyword\">new<\/code> <code class=\"java plain\">Order();<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop.createOrder(order);<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop.verifyCreateOrder(order);<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number18 index17 alt1\">&nbsp;<\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java color1\">@Test<\/code><\/div>\n<div class=\"line number20 index19 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">void<\/code> <code class=\"java plain\">testProcessUnfinishedOrders() {<\/code><\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">List&lt;Order&gt; orders = Arrays.asList(...);<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop.answerForUnfinishedOrders(orders);<\/code><\/div>\n<div class=\"line number23 index22 alt2\">&nbsp;<\/div>\n<div class=\"line number24 index23 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop.processUnfinishedOrders();<\/code><\/div>\n<div class=\"line number25 index24 alt2\">&nbsp;<\/div>\n<div class=\"line number26 index25 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">coffeeShop.verifyProcessUnfinishedOrders();<\/code><\/div>\n<div class=\"line number27 index26 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">orderProcessor.verifyProcessOrders(orders);<\/code><\/div>\n<div class=\"line number28 index27 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number29 index28 alt2\">&nbsp;<\/div>\n<div class=\"line number30 index29 alt1\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>The use case test verifies the processing of an individual business use case which is invoked on the entry point, here <code>CoffeeShop<\/code>. These tests become brief and very readable, since the wiring and mocking happens in the individual test doubles, and they can furthermore utilize use case-specific verification methods, such as <code>verifyProcessOrders()<\/code>.<\/p>\n<p>As you can see, the test double extends the production scope class for setting up the mocks and for methods to verify the behavior. While this seems like some effort to setup, the costs amortizes quickly if we have multiple use cases that can reuse the components within the whole project. The more our project grows, the bigger the benefits of this approach, especially if we look at the test execution time. All our test cases still run using JUnit, which executes hundreds of them in no time.<\/p>\n<p>This is the main benefit of this approach: that use case tests will run just as quickly as plain unit tests, yet facilitate it to refactor production code, since changes have to be made in a single or few components only. Additionally, enhancing the test doubles with expressive setup and verification methods that are specific to our domain makes our test code more readable, facilitates the usage, and avoids boilerplate code in the test cases.<\/p>\n<p>Code-level tests that don\u2019t include any advanced test context runner can be executed very quickly and don\u2019t add too much time to the overall build, even in very complex projects. The next part of the series will show code-level as well as system-level integration tests.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Sebastian Daschner, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/blog.sebastian-daschner.com\/entries\/thoughts-on-efficient-testing-unit\" target=\"_blank\" rel=\"noopener noreferrer\">Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6)<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the first part of the series we saw some generally applicable principles and constraints that effective tests should fulfill. In this part, we will have a closer look at code-level unit tests and component or use case tests. Unit tests Unit tests verify the behavior of a single unit, usually a class, while all &hellip;<\/p>\n","protected":false},"author":7568,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[273],"class_list":["post-98209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6) - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test\" \/>\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\/2019\/09\/efficient-enterprise-testing-unit-use-case.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6) - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.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=\"2019-09-15T12:15:01+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=\"Sebastian Daschner\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DaschnerS\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Daschner\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html\"},\"author\":{\"name\":\"Sebastian Daschner\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c0cd4930fe5f0a7be847ee87863ea665\"},\"headline\":\"Efficient enterprise testing \u2014 unit &amp; use case tests (2\\\/6)\",\"datePublished\":\"2019-09-15T12:15:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html\"},\"wordCount\":1186,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html\",\"name\":\"Efficient enterprise testing \u2014 unit &amp; use case tests (2\\\/6) - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2019-09-15T12:15:01+00:00\",\"description\":\"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.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\\\/2019\\\/09\\\/efficient-enterprise-testing-unit-use-case.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\":\"Efficient enterprise testing \u2014 unit &amp; use case tests (2\\\/6)\"}]},{\"@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\\\/c0cd4930fe5f0a7be847ee87863ea665\",\"name\":\"Sebastian Daschner\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g\",\"caption\":\"Sebastian Daschner\"},\"description\":\"Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.\",\"sameAs\":[\"https:\\\/\\\/blog.sebastian-daschner.com\\\/\",\"https:\\\/\\\/x.com\\\/DaschnerS\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/sebastian-daschner\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6) - Java Code Geeks","description":"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test","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\/2019\/09\/efficient-enterprise-testing-unit-use-case.html","og_locale":"en_US","og_type":"article","og_title":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6) - Java Code Geeks","og_description":"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test","og_url":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-09-15T12:15:01+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":"Sebastian Daschner","twitter_card":"summary_large_image","twitter_creator":"@DaschnerS","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Sebastian Daschner","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html"},"author":{"name":"Sebastian Daschner","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c0cd4930fe5f0a7be847ee87863ea665"},"headline":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6)","datePublished":"2019-09-15T12:15:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html"},"wordCount":1186,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html","url":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html","name":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6) - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2019-09-15T12:15:01+00:00","description":"Interested to learn about use case tests? Check our article explaining code-level unit tests and component or use case test","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2019\/09\/efficient-enterprise-testing-unit-use-case.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\/2019\/09\/efficient-enterprise-testing-unit-use-case.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":"Efficient enterprise testing \u2014 unit &amp; use case tests (2\/6)"}]},{"@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\/c0cd4930fe5f0a7be847ee87863ea665","name":"Sebastian Daschner","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c5f7cd4d32ab6265242b5c9fdb10e6be68a6a583d8863f746fd9852b8149bbd9?s=96&d=mm&r=g","caption":"Sebastian Daschner"},"description":"Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.","sameAs":["https:\/\/blog.sebastian-daschner.com\/","https:\/\/x.com\/DaschnerS"],"url":"https:\/\/www.javacodegeeks.com\/author\/sebastian-daschner"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98209","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\/7568"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=98209"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98209\/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=98209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=98209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=98209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}