<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Martin Ankerl &#187; tdd</title> <atom:link href="http://martin.ankerl.com/category/tdd/feed/" rel="self" type="application/rss+xml" /><link>http://martin.ankerl.com</link> <description>Chunky bacon!!</description> <lastBuildDate>Sat, 04 Feb 2012 10:18:10 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Statistical Unit Tests with ensure4j</title><link>http://martin.ankerl.com/2007/01/04/statistical-unit-tests-with-ensure4j/</link> <comments>http://martin.ankerl.com/2007/01/04/statistical-unit-tests-with-ensure4j/#comments</comments> <pubDate>Thu, 04 Jan 2007 20:54:33 +0000</pubDate> <dc:creator>martinus</dc:creator> <category><![CDATA[agile]]></category> <category><![CDATA[freeware]]></category> <category><![CDATA[ideas]]></category> <category><![CDATA[java]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[tdd]]></category> <category><![CDATA[ensure4j]]></category> <category><![CDATA[junit]]></category> <category><![CDATA[statistics]]></category><guid isPermaLink="false">http://martin.ankerl.com/?p=78</guid> <description><![CDATA[As part of another project I am developing ensure4j. The syntax (see the examples here) is working quite nicely, ensure4j is already very useful for internal use. Lately I was busy adding tests that are able to verify if some &#8230; <a href="http://martin.ankerl.com/2007/01/04/statistical-unit-tests-with-ensure4j/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>As part of another project I am developing <a href="http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/">ensure4j</a>. The syntax (see the examples <a href="http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/">here</a>) is working quite nicely, ensure4j is already very useful for internal use.</p><p>Lately I was busy adding tests that are able to verify if some code (e.g. an optimizer that uses random, like <a href="http://en.wikipedia.org/wiki/Genetic_algorithm">genetic algorithm</a>, <a href="http://en.wikipedia.org/wiki/Simulated_annealing">simulated annealing</a>, &#8230;) produces the desired in e.g. 95% of the cases (Wikipedia has <a href="http://en.wikipedia.org/wiki/Confidence_interval#Practical_example">a nice practical example</a> for confidence intervals).</p><h1>Example Usage</h1><p>Here is an example that tests the nonsense code <tt>Math.random() * 2</tt>.</p><pre class="brush: java; title: ; notranslate">ensure(new Experiment() {
    public double measure() {
        return Math.random() * 2;
    }
}).between(0.9, 1.1, 0.95).sample(10, 100);</pre><p>The code most likely does not make much sense out of context like this, so here is an explanation of what it does:</p><p><span id="more-78"></span></p><h1>Explanation</h1><p>In that example we want to verify that the code  returns values whose <strong>95% confidence interval is between 0.9 and 1.1</strong>. At first take <strong>10 samples</strong> to verify this. If the mean is not as expected between the interval, there is still the chance that this was just bad luck. We can take further samples (<strong>up to 1000</strong>) to rule bad luck out. When we have to take more than 1000 samples and the mean is still not in the specified  still not met, there is a very high probability that the code does not produce the desired result, so we have to fail.</p><p>I hope the above description is somewhat understandable. It&#8217;s no piece of cake, and there is no way to cheat around the complexity involved with that kind of statistical tests. I have tried to make the interface as clean and simple as possible, suggestions are always welcome.</p><h1>Open Source?</h1><p>I am developing ensure4j partly at work, and partly in my free time. I would like to make it open source, but I need to get the OK from my boss first.</p><p>ensure4j is the the only implementation I know of that uses statistical tests that can be used with JUnit. If you know something similar than this, please post!</p><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://martin.ankerl.com/2007/01/04/statistical-unit-tests-with-ensure4j/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Redesigning JUnit Asserts</title><link>http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/</link> <comments>http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/#comments</comments> <pubDate>Wed, 02 Aug 2006 20:02:18 +0000</pubDate> <dc:creator>martinus</dc:creator> <category><![CDATA[agile]]></category> <category><![CDATA[java]]></category> <category><![CDATA[programming]]></category> <category><![CDATA[tdd]]></category><guid isPermaLink="false">http://martin.ankerl.com/?p=70</guid> <description><![CDATA[After reading about Behaviour Driven Development, using jMock for a while, and since I am very fond of Ruby&#8216;s core class APIs, I am sure the assertations of JUnit need a major overhaul. This are the goals I have for &#8230; <a href="http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>After reading about <a href="/2006/08/02/behaviour-driven-development/">Behaviour Driven Development</a>, using <a href="http://www.jmock.org/">jMock</a> for a while, and since I am very fond of <a href="http://www.ruby-lang.org/en/">Ruby</a>&#8216;s <a href="http://www.rubycentral.com/ref/">core class API</a>s, I am sure the assertations of JUnit need a major overhaul.</p><p>This are the goals I have for the redesign:</p><p><span id="more-70"></span></p><ul><li>Make the code expressive and as readable as possbile. This means the code should look like plain english.</li><li>Usability is more important than flexibility.</li><li>Allow for much more poweful checks.</li></ul><p>Usability is very important. The good thing is that it is easy to analyze how JUnit is used (download some test driven developed open source projects, grep for <tt>assertTrue</tt>, and there you have all the cases where JUnit&#8217;s asserts were not good enough <img src="http://martin.ankerl.com/wp-includes/images/smilies/icon_smile.gif?9d7bd4" alt=':-)' class='wp-smiley' /> )</p><p>I am playing around with a few ideas, and this is the API I am currently after:</p><h1>Assertions Example Usage</h1><pre class="brush: java; title: ; notranslate">public void testInt() {
  int num = 4+1;
  ensure(num).is(5);
  ensure(num).either(4, 5, 6);
  ensure(num).between(3, 10);
}

public void testDouble() {
  double val = 4 + 0.4;
  // an epsilon is mandatory when comparing double
  ensure(val).is(4.4, 0.0001);
  ensure(val).between(4.3, 4.5);
}

public void testArray() {
  int[] a = { 1, 2, 3, 4, 5 };
  ensure(a).contains(3);
  ensure(a).size().either(5, 6);
  ensure(a).contains(2, 3, 4);
  ensure(a).contains().either(3, 10, 11);
  ensure(a).contains().neither(6, 7, 9);
  ensure(a).contains().any(3, 4);
  ensure(a).contains().all(3, 4, 5);
  ensure(a).isSorted();
  ensure(a).isUnique();
}</pre><p>Starting point is always <tt>ensure()</tt>. You put in the actual value, then execute some operations that modify the following constraint check, then the last command is the constraint check. The last command is always the constraint check, so you can only do one check per line of code. That&#8217;s not as flexible as jMock, but it is simpler and more readable and good enough.</p><p>Technically all this is very doable. Probably quite a bit of work, and most likely requires a code generator since lots of code is almost the same but not reusable (e.g. arrays for primitive data types), but that&#8217;s not a problem. I have done a few simple feasibility studies and I don&#8217;t see a big problem with this interface.</p><p>Please tell me what you think about this!</p><h1>Updates</h1><p>From time to time I will update this page with progress reports, until I have something that is stable enough to give away.</p><dl><dt><strong>2006-08-05</strong></dt><dd>I have started developing this. So far I am very happy with it, its a fun project to implement <img src="http://martin.ankerl.com/wp-includes/images/smilies/icon_smile.gif?9d7bd4" alt=':-)' class='wp-smiley' /> I will probably create a project on sourceforge and opensource it, but I am not sure about the licence.</dd></dl><div style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://martin.ankerl.com/2006/08/02/redesigning-junit-asserts/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/23 queries in 0.058 seconds using disk: basic
Object Caching 535/574 objects using disk: basic

Served from: martin.ankerl.com @ 2012-02-04 11:18:33 -->
