{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "chem-bla-ics",
  "description": "Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.",
  "home_page_url": "https://chem-bla-ics.linkedchemistry.info/",
  "feed_url": "https://chem-bla-ics.linkedchemistry.info/2010/08/14/specifying-unit-test-dependencies-with.json",
  "icon": "https://chem-bla-ics.linkedchemistry.info/assets/images/chem-bla-ics_logo.png",
  "language": "en",
  "authors": [
    {
      "name": "Egon Willighagen",
      "url": "https://orcid.org/0000-0001-7542-0286",
      "_orcid": "0000-0001-7542-0286"
    }
  ],
  "items": [

    {
      "id": "https://doi.org/10.59350/4xeej-wct60",
      "url": "https://chem-bla-ics.linkedchemistry.info/2010/08/14/specifying-unit-test-dependencies-with.html",
      "title": "Specifying unit test dependencies with JExample",
      "content_html": "<p>A while ago <a href=\"http://stackoverflow.com/questions/2584629/how-can-i-specifiy-junit-test-dependencies\">I asked on StackOverflow</a> about options\nto specify unit test dependencies. An example from the <a href=\"http://cdk.sf.net/\">CDK</a> would be that aromaticity detection in some molecule would\nrequire that all atom types are correctly perceived. I could test both in separate unit tests, but with <a href=\"http://www.junit.org/\">JUnit</a> I\ncannot have the aromaticity test ignored of the atom typing already failed. Now, being to specify such dependencies is useful, as the failing\naromaticity test may be caused by the faulty atom typing, but the failing aromaticity test seems to imply something is wrong with the\naromaticity detection algorithm.</p>\n\n<p>One of the answers was <a href=\"http://scg.unibe.ch/research/jexample\">JExample</a>. Consider this code:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nd\">@RunWith</span><span class=\"o\">(</span><span class=\"nc\">JExample</span><span class=\"o\">.</span><span class=\"na\">class</span><span class=\"o\">)</span>\n<span class=\"kd\">public</span> <span class=\"kd\">class</span> <span class=\"nc\">MoleculeTest</span> <span class=\"o\">{</span>\n\n  <span class=\"nd\">@Test</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">MoleculeFactory</span> <span class=\"nf\">testNewMoleculeFactory</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"nc\">Assert</span><span class=\"o\">.</span><span class=\"na\">fail</span><span class=\"o\">(</span><span class=\"s\">\"too bad\"</span><span class=\"o\">);</span>\n    <span class=\"k\">return</span> <span class=\"k\">new</span> <span class=\"nf\">MoleculeFactory</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n\n  <span class=\"nd\">@Given</span><span class=\"o\">(</span><span class=\"s\">\"#testNewMoleculeFactory()\"</span><span class=\"o\">)</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">IMolecule</span> <span class=\"nf\">testNewMolecule</span><span class=\"o\">(</span><span class=\"nc\">MoleculeFactory</span> <span class=\"n\">factory</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"nc\">Assert</span><span class=\"o\">.</span><span class=\"na\">fail</span><span class=\"o\">(</span><span class=\"s\">\"too bad\"</span><span class=\"o\">);</span>\n    <span class=\"k\">return</span> <span class=\"n\">factory</span><span class=\"o\">.</span><span class=\"na\">getImmutable</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n\n<span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>Reading this Java code requires some experience with JUnit4, but those who already know JUnit4 will also see that the code is somewhat\nunusual. For of all, we define a special class to run the tests with: <em>JExample.class</em>. A second thing to note is that the top test method\nactually returns something. The bottom test method is also differnt: instead of being annotated with <em>@Test</em>, it is annotated with\n<em>@Given</em>. This latter annotation is introduced by JExample to define the dependencies between the tests. The parameter of this annotation\ndefines which test method it depends on. Moreover, it is now also clear what happens with the return value of the top test method: it is\npassed as argument to the second test method.</p>\n\n<p>Just to show that the system actually works, you can find a screenshot of the <a href=\"http://www.eclipse.org/\">Eclipse</a> JUnit View\n(the JExample update site did not work with Eclipse 3.6, so I have the JExample jar defined as build dependency in the project instead):</p>\n\n<p><img src=\"/assets/images/jexample.png\" alt=\"\" /></p>\n\n<p>Clearly, only one test failed, while the <em>testNewMolecule()</em> method was ignored.</p>\n\n<p>Now, I was wondering if the first method could be reused, and if so, if it would construct a new object. And it does, as is clear from the output of this code:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>  <span class=\"nd\">@Test</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">MoleculeFactory</span> <span class=\"nf\">testNewMoleculeFactory</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"k\">return</span> <span class=\"k\">new</span> <span class=\"nf\">MoleculeFactory</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n\n  <span class=\"nd\">@Given</span><span class=\"o\">(</span><span class=\"s\">\"#testNewMoleculeFactory()\"</span><span class=\"o\">)</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">IMolecule</span> <span class=\"nf\">testNewMolecule</span><span class=\"o\">(</span><span class=\"nc\">MoleculeFactory</span> <span class=\"n\">factory</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"nc\">System</span><span class=\"o\">.</span><span class=\"na\">out</span><span class=\"o\">.</span><span class=\"na\">println</span><span class=\"o\">(</span><span class=\"s\">\"Factory1: \"</span> <span class=\"o\">+</span> <span class=\"n\">factory</span><span class=\"o\">);</span>\n    <span class=\"k\">return</span> <span class=\"n\">factory</span><span class=\"o\">.</span><span class=\"na\">getImmutable</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n\n  <span class=\"nd\">@Given</span><span class=\"o\">(</span><span class=\"s\">\"#testNewMoleculeFactory()\"</span><span class=\"o\">)</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">IMolecule</span> <span class=\"nf\">testNewMolecule2</span><span class=\"o\">(</span><span class=\"nc\">MoleculeFactory</span> <span class=\"n\">factory</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"nc\">System</span><span class=\"o\">.</span><span class=\"na\">out</span><span class=\"o\">.</span><span class=\"na\">println</span><span class=\"o\">(</span><span class=\"s\">\"Factory2: \"</span> <span class=\"o\">+</span> <span class=\"n\">factory</span><span class=\"o\">);</span>\n    <span class=\"k\">return</span> <span class=\"n\">factory</span><span class=\"o\">.</span><span class=\"na\">getImmutable</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>which outputs:</p>\n\n<div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>Factory2: com.github.egonw.odk.model.MoleculeFactory@7bd63e39\nFactory1: com.github.egonw.odk.model.MoleculeFactory@42b988a6\n</code></pre></div></div>\n\n<p>This seems pretty useful. I am not sure yet if it solves all my dependency requirements, though. For example, what I really like to do, is link more complex tests to more than one more simpler tests, where it is clear that the complexer test will fail if one or more of the simpler tests fail. However, the JExample examples suggest that I can only define one dependency, whereas, for example, aromaticity detection depends on correct atom type perception, but also on ring detection. For now, this is a welcome extension of JUnit.</p>\n\n\n<h4>References</h4>\n<div class=\"csl-bib-body\">\n    <div class=\"csl-entry\">Kuhn, A., Van Rompaey, B., Haensenberger, L., Nierstrasz, O., Demeyer, S., Gaelli, M., &#38; Van Leemput, K. (2008). JExample: Exploiting Dependencies between Tests to Improve Defect Localization. In <i>Lecture Notes in Business Information Processing</i> (pp. 73–82). Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-540-68255-4_8 <a href=\"https://doi.org/10.1007/978-3-540-68255-4_8\">CrossRef</a> <a href=\"https://qlever.scholia.wiki/doi/10.1007/978-3-540-68255-4_8\">Scholia</a></div>\n  </div>",
      "summary": "A while ago I asked on StackOverflow about options to specify unit test dependencies. An example from the CDK would be that aromaticity detection in some molecule would require that all atom types are correctly perceived. I could test both in separate unit tests, but with JUnit I cannot have the aromaticity test ignored of the atom typing already failed. Now, being to specify such dependencies is useful, as the failing aromaticity test may be caused by the faulty atom typing, but the failing aromaticity test seems to imply something is wrong with the aromaticity detection algorithm.",
      "image": "https://chem-bla-ics.linkedchemistry.info/assets/images/jexample.png",
      "date_published": "2010-08-14T00:10:00+00:00",
      "date_modified": "2026-08-17T00:00:00+00:00",
      "tags": ["java","junit"],
      "_references": [
        
          
          
            { "url": "https://doi.org/10.1007/978-3-540-68255-4_8", "doi": "10.1007/978-3-540-68255-4_8"
             }
            
          
        ],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
