{"id":680,"date":"2011-11-21T10:20:00","date_gmt":"2011-11-21T10:20:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/what-should-you-unit-test-testing-techniques-3.html"},"modified":"2012-10-21T20:38:17","modified_gmt":"2012-10-21T20:38:17","slug":"what-should-you-unit-test-testing","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html","title":{"rendered":"What Should you Unit Test? &#8211; Testing Techniques 3"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests.<\/p>\n<p>One of the reasons that he was using was that some tests seem meaningless, which brings me on the the subject of what exactly you unit test, and what you don\u2019t need to bother with.<\/p>\n<p>Consider a simple immutable Name bean below with a constructor and a bunch of getters.<\/p>\n<p>In this example I\u2019m going to let the code speak for itself as I hope that it\u2019s obvious that any testing would be pointless.<\/p>\n<pre class=\"brush: java;\">public class Name {\r\n\r\n  private final String firstName;\r\n  private final String middleName;\r\n  private final String surname;\r\n\r\n  public Name(String christianName, String middleName, String surname) {\r\n    this.firstName = christianName;\r\n    this.middleName = middleName;\r\n    this.surname = surname;\r\n  }\r\n\r\n  public String getFirstName() {\r\n    return firstName;\r\n  }\r\n\r\n  public String getMiddleName() {\r\n    return middleName;\r\n  }\r\n\r\n  public String getSurname() {\r\n    return surname;\r\n  }\r\n}\r\n<\/pre>\n<p>&#8230;and just to underline the point, here is the pointless test code:<\/p>\n<pre class=\"brush: java;\">public class NameTest {\r\n\r\n  private Name instance;\r\n\r\n  @Before\r\n  public void setUp() {\r\n    instance = new Name(\"John\", \"Stephen\", \"Smith\");\r\n  }\r\n\r\n  @Test\r\n  public void testGetFirstName() {\r\n    String result = instance.getFirstName();\r\n    assertEquals(\"John\", result);\r\n  }\r\n\r\n  @Test\r\n  public void testGetMiddleName() {\r\n    String result = instance.getMiddleName();\r\n    assertEquals(\"Stephen\", result);\r\n  }\r\n\r\n  @Test\r\n  public void testGetSurname() {\r\n    String result = instance.getSurname();\r\n    assertEquals(\"Smith\", result);\r\n  }\r\n}\r\n<\/pre>\n<p>The reason it\u2019s pointless testing this class is that the code doesn\u2019t contain any logic; however, the moment you add something like this to the Name class:<\/p>\n<pre class=\"brush: java;\">public String getFullName() {\r\n\r\n    if (isValidString(firstName) &amp;&amp; isValidString(middleName) &amp;&amp; isValidString(surname)) {\r\n      return firstName + \" \" + middleName + \" \" + surname;\r\n    } else {\r\n      throw new RuntimeException(\"Invalid Name Values\");\r\n    }\r\n  }\r\n\r\n  private boolean isValidString(String str) {\r\n    return isNotNull(str) &amp;&amp; str.length() &gt; 0;\r\n  }\r\n\r\n  private boolean isNotNull(Object obj) {\r\n    return obj != null;\r\n  }\r\n<\/pre>\n<p>&#8230;then the whole situation changes. Adding some logic in the form of an if statement generates a whole bunch of tests:<\/p>\n<pre class=\"brush: java;\">@Test\r\n  public void testGetFullName_with_valid_input() {\r\n\r\n    instance = new Name(\"John\", \"Stephen\", \"Smith\");\r\n\r\n    final String expected = \"John Stephen Smith\";\r\n\r\n    String result = instance.getFullName();\r\n    assertEquals(expected, result);\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_null_firstName() {\r\n\r\n    instance = new Name(null, \"Stephen\", \"Smith\");\r\n    instance.getFullName();\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_null_middleName() {\r\n\r\n    instance = new Name(\"John\", null, \"Smith\");\r\n    instance.getFullName();\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_null_surname() {\r\n\r\n    instance = new Name(\"John\", \"Stephen\", null);\r\n    instance.getFullName();\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_no_firstName() {\r\n\r\n    instance = new Name(\"\", \"Stephen\", \"Smith\");\r\n    instance.getFullName();\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_no_middleName() {\r\n\r\n    instance = new Name(\"John\", \"\", \"Smith\");\r\n    instance.getFullName();\r\n  }\r\n\r\n  @Test(expected = RuntimeException.class)\r\n  public void testGetFullName_with_no_surname() {\r\n\r\n    instance = new Name(\"John\", \"Stephen\", \"\");\r\n    instance.getFullName();\r\n  }\r\n<\/pre>\n<p>So, given that I\u2019ve just said that you shouldn&#8217;t need to test objects that do not contain any logic statements, and in a list of <i>logic<\/i> <i>statements<\/i> I\u2019d include if and <strong>switch<\/strong> together with all the operators (+-*-), and a whole bundle of things that could change and objects state.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Given this premise, I\u2019d then suggest that it\u2019s pointless writing a unit test for the address data access object (DAO) in the <a href=\"\/\/github.com\/roghughe\/captaindebug.git\">Address<\/a> project I\u2019ve been talking about in my last couple of blogs. The DAO is defined by the <strong>AddressDao<\/strong> interface and implemented by the <strong>JdbcAddress<\/strong> class:<\/p>\n<pre class=\"brush: java;\">public class JdbcAddress extends JdbcDaoSupport implements AddressDao {\r\n\r\n  \/**\r\n   * This is an instance of the query object that'll sort out the results of\r\n   * the SQL and produce whatever values objects are required\r\n   *\/\r\n  private MyQueryClass query;\r\n\r\n  \/** This is the SQL with which to run this DAO *\/\r\n  private static final String sql = \"select * from addresses where id = ?\";\r\n\r\n  \/**\r\n   * A class that does the mapping of row data into a value object.\r\n   *\/\r\n  class MyQueryClass extends MappingSqlQuery&lt;address&gt; {\r\n\r\n    public MyQueryClass(DataSource dataSource, String sql) {\r\n      super(dataSource, sql);\r\n      this.declareParameter(new SqlParameter(Types.INTEGER));\r\n    }\r\n\r\n    \/**\r\n     * This the implementation of the MappingSqlQuery abstract method. This\r\n     * method creates and returns a instance of our value object associated\r\n     * with the table \/ select statement.\r\n     * \r\n     * @param rs\r\n     *            This is the current ResultSet\r\n     * @param rowNum\r\n     *            The rowNum\r\n     * @throws SQLException\r\n     *             This is taken care of by the Spring stuff...\r\n     *\/\r\n    @Override\r\n    protected Address mapRow(ResultSet rs, int rowNum) throws SQLException {\r\n\r\n      return new Address(rs.getInt(\"id\"), rs.getString(\"street\"),\r\n          rs.getString(\"town\"), rs.getString(\"post_code\"),\r\n          rs.getString(\"country\"));\r\n    }\r\n  }\r\n\r\n  \/**\r\n   * Override the JdbcDaoSupport method of this name, calling the super class\r\n   * so that things get set-up correctly and then create the inner query\r\n   * class.\r\n   *\/\r\n  @Override\r\n  protected void initDao() throws Exception {\r\n    super.initDao();\r\n    query = new MyQueryClass(getDataSource(), sql);\r\n  }\r\n\r\n  \/**\r\n   * Return an address object based upon it's id\r\n   *\/\r\n  @Override\r\n  public Address findAddress(int id) {\r\n    return query.findObject(id);\r\n  }\r\n\r\n}\r\n<\/pre>\n<p>In the code above, the only method in the interface is:<\/p>\n<pre class=\"brush: java;\">@Override\r\n  public Address findAddress(int id) {\r\n    return query.findObject(id);\r\n  }\r\n<\/pre>\n<p>&#8230;which is really a simple getter method. This seems okay to me as there really should not be any business logic in a DAO, that belongs in the <strong>AddressService<\/strong>, which should have a plentiful supply of unit tests.<\/p>\n<p><span class=\"Apple-style-span\" style=\"background-color: #a2c4c9\">You may want to make a decision on whether or not you want to write unit tests for the MyQueryClass. To me this is a borderline case, so I look forward to any comments&#8230;<\/span><\/p>\n<p>I\u2019m guessing that someone will disagree with this approach, say you should test the <strong>JdbcAddress<\/strong> object and that\u2019s true, I\u2019d personally write an <i>integration<\/i> test for it to make sure that the database I\u2019m using is okay, that it understands my SQL and that the two entities (DAO and database) can talk to each other, but I won\u2019t bother <i>unit<\/i> testing it.<\/p>\n<p>To conclude, unit tests must be meaningful, and a good a definition of \u2018meaningful\u2019 is that object under test must contain some independent logic.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.captaindebug.com\/2011\/11\/what-should-you-unit-test-testing.html\">What Should you Unit Test? &#8211; Testing Techniques 3<\/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\/regular-unit-tests-and-stubs-testing.html\">Regular Unit Tests and Stubs &#8211; Testing Techniques 4<\/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>I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that he was using was that some tests seem meaningless, which brings me on the the subject of what exactly you unit test, and what you don\u2019t need &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-680","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>What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that\" \/>\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\/what-should-you-unit-test-testing.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-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-21T10:20:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:38:17+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\\\/what-should-you-unit-test-testing.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html\"},\"author\":{\"name\":\"Roger Hughes\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\"},\"headline\":\"What Should you Unit Test? &#8211; Testing Techniques 3\",\"datePublished\":\"2011-11-21T10:20:00+00:00\",\"dateModified\":\"2012-10-21T20:38:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html\"},\"wordCount\":548,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-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\\\/what-should-you-unit-test-testing.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html\",\"name\":\"What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"datePublished\":\"2011-11-21T10:20:00+00:00\",\"dateModified\":\"2012-10-21T20:38:17+00:00\",\"description\":\"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-testing.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/what-should-you-unit-test-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\\\/what-should-you-unit-test-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\":\"What Should you Unit Test? &#8211; Testing Techniques 3\"}]},{\"@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":"What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks","description":"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that","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\/what-should-you-unit-test-testing.html","og_locale":"en_US","og_type":"article","og_title":"What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks","og_description":"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that","og_url":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-11-21T10:20:00+00:00","article_modified_time":"2012-10-21T20:38:17+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\/what-should-you-unit-test-testing.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html"},"author":{"name":"Roger Hughes","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07"},"headline":"What Should you Unit Test? &#8211; Testing Techniques 3","datePublished":"2011-11-21T10:20:00+00:00","dateModified":"2012-10-21T20:38:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html"},"wordCount":548,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-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\/what-should-you-unit-test-testing.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html","url":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html","name":"What Should you Unit Test? - Testing Techniques 3 - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","datePublished":"2011-11-21T10:20:00+00:00","dateModified":"2012-10-21T20:38:17+00:00","description":"I was in the office yesterday, talking about testing to one of my colleagues who was a little unconvinced by writing unit tests. One of the reasons that","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-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\/what-should-you-unit-test-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":"What Should you Unit Test? &#8211; Testing Techniques 3"}]},{"@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\/680","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=680"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/680\/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=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}