{"id":677,"date":"2011-11-22T16:41:00","date_gmt":"2011-11-22T16:41:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/regular-unit-tests-and-stubs-testing-techniques-4.html"},"modified":"2012-10-21T20:37:42","modified_gmt":"2012-10-21T20:37:42","slug":"regular-unit-tests-and-stubs-testing","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html","title":{"rendered":"Regular Unit Tests and Stubs &#8211; Testing Techniques 4"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my simple scenario of retrieving an address from a database using a very common pattern:<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/3.bp.blogspot.com\/-yH4AkqVLOAg\/TrvNnaMIzKI\/AAAAAAAAAXk\/6xOz3GWqj9U\/s320\/Screen+Shot+2011-11-10+at+12.58.52.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-yH4AkqVLOAg\/TrvNnaMIzKI\/AAAAAAAAAXk\/6xOz3GWqj9U\/s320\/Screen+Shot+2011-11-10+at+12.58.52.png\" \/><\/a><\/div>\n<p>&#8230;and I proffered the idea that any class that doesn\u2019t contain any logic doesn\u2019t really need unit testing. In this I included my data access object, DAO, preferring instead to integration test this class to ensure it worked in collaboration with the database.<\/p>\n<p>Today\u2019s blog covers writing a regular or classical unit test that enforces test subject isolation using stub objects. The code we\u2019ll be testing is, again, the <strong>AddressService<\/strong>:<\/p>\n<pre class=\"brush: java;\">@Component\r\npublic class AddressService {\r\n\r\n  private static final Logger logger = LoggerFactory.getLogger(AddressService.class);\r\n\r\n  private AddressDao addressDao;\r\n\r\n  \/**\r\n   * Given an id, retrieve an address. Apply phony business rules.\r\n   * \r\n   * @param id\r\n   *            The id of the address object.\r\n   *\/\r\n  public Address findAddress(int id) {\r\n\r\n    logger.info(\"In Address Service with id: \" + id);\r\n    Address address = addressDao.findAddress(id);\r\n\r\n    address = businessMethod(address);\r\n\r\n    logger.info(\"Leaving Address Service with id: \" + id);\r\n    return address;\r\n  }\r\n\r\n  private Address businessMethod(Address address) {\r\n\r\n    logger.info(\"in business method\");\r\n\r\n    \/\/ Apply the Special Case Pattern (See MartinFowler.com)\r\n    if (isNull(address)) {\r\n      address = Address.INVALID_ADDRESS;\r\n    }\r\n\r\n    \/\/ Do some jiggery-pokery here....\r\n\r\n    return address;\r\n  }\r\n\r\n  private boolean isNull(Object obj) {\r\n    return obj == null;\r\n  }\r\n\r\n  @Autowired\r\n  @Qualifier(\"addressDao\")\r\n  void setAddressDao(AddressDao addressDao) {\r\n    this.addressDao = addressDao;\r\n  }\r\n}\r\n<\/pre>\n<p>Michael Feather\u2019s book Working Effectively with Legacy Code states that a test is not a unit test if:<\/p>\n<ol style=\"text-align: left\">\n<li>It talks to a database.<\/li>\n<li>It communicates across a network.<\/li>\n<li>It touches the file system.<\/li>\n<li>You have to do special things to your environment (such as editing configuration files) to run it.<\/li>\n<\/ol>\n<p>To uphold these rules, you need to isolate your object under test from the rest of your system, and that\u2019s where stub objects come in. Stub objects are objects that are injected into your object and are used to replace real objects in test situations. Martin Fowler defines stubs, in his essay <a href=\"http:\/\/martinfowler.com\/articles\/mocksArentStubs.html\">Mocks Aren\u2019t Stubs<\/a> as:<\/p>\n<p>\u201cStubs provide canned answers to calls made during the test, usually not responding at all to anything outside what&#8217;s programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it &#8216;sent&#8217;, or maybe only how many messages it &#8216;sent&#8217;\u201d.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">Picking a word to describe stubs is very difficult, I could choose dummy or fake, but there are types of replacement object that are known as dummies or fakes &#8211; also described by Martin Fowler:<\/span><\/p>\n<ul style=\"text-align: left\">\n<li><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.<\/span><\/li>\n<li><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).<\/span><\/li>\n<\/ul>\n<p><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">However, I have seen other definitions of the term fake object,for example Roy Osherove in is book The Art Of Unit Testing defines a fakes object as:<\/span><\/p>\n<ul style=\"text-align: left\">\n<li><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">A fake is a generic term that can be used to describe either a stub or a mock object&#8230;because the both look like the real object.<\/span><\/li>\n<\/ul>\n<p><span class=\"Apple-style-span\" style=\"background-color: #d0e0e3\">&#8230;so I, like many others, tend to call all replacement objects either mocks or stubs as there is a difference between the two, but more on that later.<\/span><\/p>\n<p>In testing the <strong>AddressService<\/strong>, we need to replace the real data access object with a stub data access object and in this case, it looks something like this:<\/p>\n<pre class=\"brush: java;\">public class StubAddressDao implements AddressDao {\r\n\r\n  private final Address address;\r\n\r\n  public StubAddressDao(Address address) {\r\n    this.address = address;\r\n  }\r\n\r\n  \/**\r\n   * @see com.captaindebug.address.AddressDao#findAddress(int)\r\n   *\/\r\n  @Override\r\n  public Address findAddress(int id) {\r\n    return address;\r\n  }\r\n}\r\n<\/pre>\n<p>Note the simplicity of the stub code. It should be easily readable, maintainable and NOT contain any logic and need a unit test of its own. Once the stub code has been written, next follows the unit test:<\/p>\n<pre class=\"brush: java;\">public class ClassicAddressServiceWithStubTest {\r\n\r\n  private AddressService instance;\r\n\r\n  @Before\r\n  public void setUp() throws Exception {\r\n    \/* Create the object to test *\/\r\n    \/* Setup data that's used by ALL tests in this class *\/\r\n    instance = new AddressService();\r\n  }\r\n\r\n  \/**\r\n   * Test method for\r\n   * {@link com.captaindebug.address.AddressService#findAddress(int)}.\r\n   *\/\r\n  @Test\r\n  public void testFindAddressWithStub() {\r\n\r\n    \/* Setup the test data - stuff that's specific to this test *\/\r\n    Address expectedAddress = new Address(1, \"15 My Street\", \"My Town\",\r\n        \"POSTCODE\", \"My Country\");\r\n    instance.setAddressDao(new StubAddressDao(expectedAddress));\r\n\r\n    \/* Run the test *\/\r\n    Address result = instance.findAddress(1);\r\n\r\n    \/* Assert the results *\/\r\n    assertEquals(expectedAddress.getId(), result.getId());\r\n    assertEquals(expectedAddress.getStreet(), result.getStreet());\r\n    assertEquals(expectedAddress.getTown(), result.getTown());\r\n    assertEquals(expectedAddress.getPostCode(), result.getPostCode());\r\n    assertEquals(expectedAddress.getCountry(), result.getCountry());\r\n  }\r\n\r\n  @After\r\n  public void tearDown() {\r\n    \/*\r\n     * Clear up to ensure all tests in the class are isolated from each\r\n     * other.\r\n     *\/\r\n  }\r\n}\r\n<\/pre>\n<p>Note that in writing a unit test, we\u2019re aiming for clarity. A mistake often made is to regard test code as inferior to production code with the result that it\u2019s often messier and more illegible. Roy Osherove in <i>The Art of Unit Testing<\/i> puts forward the idea that test code should be more readable that production code. Clear tests should follow these basic, linear steps:<\/p>\n<ol style=\"text-align: left\">\n<li>Create the object under test. In the code above this is done in the <strong><i>setUp()<\/i><\/strong> method as I\u2019m using the same object under test for all (one) tests.<\/li>\n<li>Setup the test. This is done in the test method <strong><i>testFindAddressWithStub()<\/i><\/strong> as the data used in a test is specific to that test.<\/li>\n<li>Run the Test<\/li>\n<li>Tear down the test. This ensures that tests are isolated from each other and can be run IN ANY ORDER.<\/li>\n<\/ol>\n<p>Using a simplistic stub yields the two benefits of isolating the <strong>AddressService<\/strong> from the outside world and tests that run quickly.<\/p>\n<p>How brittle is this kind of test? If your requirements change then the test and the stub changes &#8211; not so brittle after all?<\/p>\n<p>As a comparison, my next blog re-writes this test using <a href=\"http:\/\/easymock.org\/\">EasyMock<\/a>.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.captaindebug.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html\">Regular Unit Tests and Stubs &#8211; Testing Techniques 4<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> <span class=\"post-author vcard\"><span class=\"fn\">Roger Hughes <\/span><\/span>at the <a href=\"http:\/\/www.captaindebug.com\/\">Captain Debug blog<\/a><\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/testing-techniques-not-writing-tests.html\">Testing Techniques &#8211; Not Writing Tests<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/misuse-of-end-to-end-tests-testing.html\">The Misuse of End To End Tests &#8211; Testing Techniques 2<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html\">What Should you Unit Test? &#8211; Testing Techniques 3<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/unit-testing-using-mocks-testing.html\">Unit Testing Using Mocks &#8211; Testing Techniques 5<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html\">Creating Stubs for Legacy Code &#8211; Testing Techniques 6<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/more-on-creating-stubs-for-legacy-code.html\">More on Creating Stubs for Legacy Code &#8211; Testing Techniques 7<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/why-you-should-write-unit-tests-testing.html\">Why You Should Write Unit Tests &#8211; Testing Techniques 8<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/some-definitions-testing-techniques-9.html\">Some Definitions &#8211; Testing Techniques 9<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/02\/using-findbugs-to-produce-substantially.html\">Using FindBugs to produce substantially less buggy code<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/developing-and-testing-in-cloud.html\">Developing and Testing in the Cloud<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my simple scenario of retrieving an address from a database using a very common pattern: &#8230;and I proffered the idea that any class that doesn\u2019t contain &hellip;<\/p>\n","protected":false},"author":65,"featured_media":176,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[274,273],"class_list":["post-677","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-junit","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my\" \/>\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\/2011\/11\/regular-unit-tests-and-stubs-testing.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.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=\"2011-11-22T16:41:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:37:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.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=\"Roger Hughes\" \/>\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=\"Roger Hughes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html\"},\"author\":{\"name\":\"Roger Hughes\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\"},\"headline\":\"Regular Unit Tests and Stubs &#8211; Testing Techniques 4\",\"datePublished\":\"2011-11-22T16:41:00+00:00\",\"dateModified\":\"2012-10-21T20:37:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html\"},\"wordCount\":814,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"keywords\":[\"JUnit\",\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html\",\"name\":\"Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"datePublished\":\"2011-11-22T16:41:00+00:00\",\"dateModified\":\"2012-10-21T20:37:42+00:00\",\"description\":\"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/regular-unit-tests-and-stubs-testing.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\":\"Regular Unit Tests and Stubs &#8211; Testing Techniques 4\"}]},{\"@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\\\/c9feacaf8e783104a69621cd65bf1f07\",\"name\":\"Roger Hughes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"caption\":\"Roger Hughes\"},\"sameAs\":[\"http:\\\/\\\/www.captaindebug.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Roger-Hughes\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks","description":"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my","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\/2011\/11\/regular-unit-tests-and-stubs-testing.html","og_locale":"en_US","og_type":"article","og_title":"Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks","og_description":"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my","og_url":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-11-22T16:41:00+00:00","article_modified_time":"2012-10-21T20:37:42+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","type":"image\/jpeg"}],"author":"Roger Hughes","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Roger Hughes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html"},"author":{"name":"Roger Hughes","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07"},"headline":"Regular Unit Tests and Stubs &#8211; Testing Techniques 4","datePublished":"2011-11-22T16:41:00+00:00","dateModified":"2012-10-21T20:37:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html"},"wordCount":814,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","keywords":["JUnit","Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html","url":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html","name":"Regular Unit Tests and Stubs - Testing Techniques 4 - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","datePublished":"2011-11-22T16:41:00+00:00","dateModified":"2012-10-21T20:37:42+00:00","description":"My last blog was the third in a series of blogs on approaches to testing code and discussing what you do and don\u2019t have to test. It\u2019s based around my","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.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":"Regular Unit Tests and Stubs &#8211; Testing Techniques 4"}]},{"@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\/c9feacaf8e783104a69621cd65bf1f07","name":"Roger Hughes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","caption":"Roger Hughes"},"sameAs":["http:\/\/www.captaindebug.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Roger-Hughes"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/677","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\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/677\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/176"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}