<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: JUnit Theories: First Thoughts</title>
	<atom:link href="http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: @JohnArrowwood</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-36472</link>
		<dc:creator>@JohnArrowwood</dc:creator>
		<pubDate>Mon, 10 May 2010 13:28:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-36472</guid>
		<description>I agree with much of what you say but random is still a poor way to generate the data.  With the random approach you may never expose the flaw.  I would prefer intelligent selected slices with bias based on production data.

I quote from http://xunitpatterns.com/Generated%20Value.html

Variation: Random Generated Value

One way to get good test coverage without spending a lot of time analyzing the behavior and generating test conditions is to use different values each time we run the tests. Using a Random Generated Value is one way to do this. While this may seem like a good idea, it makes the tests non-deterministic and can make debugging failed tests very difficult. Ideally, when a test fails, we want to be able to repeat that test failure on demand. This can be made possible by logging the Random Generated Value as the test is run and showing it as part of the test failure. We then need to find a way to force the test to use that value when we are troubleshooting the failed test. In most cases all this is too much effort for the potential benefit but when we need this technique, we really need it.</description>
		<content:encoded><![CDATA[<p>I agree with much of what you say but random is still a poor way to generate the data.  With the random approach you may never expose the flaw.  I would prefer intelligent selected slices with bias based on production data.</p>
<p>I quote from <a href="http://xunitpatterns.com/Generated%20Value.html" rel="nofollow">http://xunitpatterns.com/Generated%20Value.html</a></p>
<p>Variation: Random Generated Value</p>
<p>One way to get good test coverage without spending a lot of time analyzing the behavior and generating test conditions is to use different values each time we run the tests. Using a Random Generated Value is one way to do this. While this may seem like a good idea, it makes the tests non-deterministic and can make debugging failed tests very difficult. Ideally, when a test fails, we want to be able to repeat that test failure on demand. This can be made possible by logging the Random Generated Value as the test is run and showing it as part of the test failure. We then need to find a way to force the test to use that value when we are troubleshooting the failed test. In most cases all this is too much effort for the potential benefit but when we need this technique, we really need it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Arrowwood</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-35950</link>
		<dc:creator>John Arrowwood</dc:creator>
		<pubDate>Sun, 02 May 2010 20:10:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-35950</guid>
		<description>@Martin:  Regarding randomization of test data:  Your own comment disproves your point.  If you have random data and you get a failure, then that suggests that you have a flaw.  Clearly, your static tests didn&#039;t isolate the flaw.  Had you relied on them, you would be blissfully ignorant of the flaw.

If you have identified your test cases with adequate thoroughness, you would not need randomness.  Every variant that could produce a different result is tested.  Code coverage analysis helps in this regard.  

But with a sufficiently complex process that you are testing, having 100% code coverage does not mean that you are bug free.  Using random input data, and knowing what the correct output should be, is a form of model-based testing, and it is valid.

Another approach that is more methodical is to generate every possible permutation of inputs (assuming that there are not an infinite number of them) and doing so programmatically, and using your model to know the expected output.  Then, you can generate your test cases.  

Sometimes, though, you can filter this down significantly by using equivalence classes.  

Still other times, knowing what kind of data may get thrown at your code is hard to predict.  Analysis of production data helps there.  Unfortunately, you can seldom test against ALL of production code.  And testing a subset means a lot of redundant testing, and the possibility of missing important test cases.  In that situation, apply equivalence classes to individual records, and divide the production data into the smallest set of records that gives you representation of every known class of data.  I once did this to a nearly half-billion record data set, and the result was around 0.25%.  Yes, that&#039;s 1/4th of one percent.  There is a lot of redundancy in production data.</description>
		<content:encoded><![CDATA[<p>@Martin:  Regarding randomization of test data:  Your own comment disproves your point.  If you have random data and you get a failure, then that suggests that you have a flaw.  Clearly, your static tests didn&#8217;t isolate the flaw.  Had you relied on them, you would be blissfully ignorant of the flaw.</p>
<p>If you have identified your test cases with adequate thoroughness, you would not need randomness.  Every variant that could produce a different result is tested.  Code coverage analysis helps in this regard.  </p>
<p>But with a sufficiently complex process that you are testing, having 100% code coverage does not mean that you are bug free.  Using random input data, and knowing what the correct output should be, is a form of model-based testing, and it is valid.</p>
<p>Another approach that is more methodical is to generate every possible permutation of inputs (assuming that there are not an infinite number of them) and doing so programmatically, and using your model to know the expected output.  Then, you can generate your test cases.  </p>
<p>Sometimes, though, you can filter this down significantly by using equivalence classes.  </p>
<p>Still other times, knowing what kind of data may get thrown at your code is hard to predict.  Analysis of production data helps there.  Unfortunately, you can seldom test against ALL of production code.  And testing a subset means a lot of redundant testing, and the possibility of missing important test cases.  In that situation, apply equivalence classes to individual records, and divide the production data into the smallest set of records that gives you representation of every known class of data.  I once did this to a nearly half-billion record data set, and the result was around 0.25%.  Yes, that&#8217;s 1/4th of one percent.  There is a lot of redundancy in production data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Harris</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-35762</link>
		<dc:creator>Martin Harris</dc:creator>
		<pubDate>Wed, 28 Apr 2010 12:48:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-35762</guid>
		<description>Just a note on randomizing the data.  This is never a good idea.  If your testing boundaries, they are easy to work out but should be fixed.  There are constants available for most in java.  If you have your own provide boundary constants.

Random data = random failure which is very hard to track down.</description>
		<content:encoded><![CDATA[<p>Just a note on randomizing the data.  This is never a good idea.  If your testing boundaries, they are easy to work out but should be fixed.  There are constants available for most in java.  If you have your own provide boundary constants.</p>
<p>Random data = random failure which is very hard to track down.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Di</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-26267</link>
		<dc:creator>Di</dc:creator>
		<pubDate>Fri, 06 Nov 2009 16:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-26267</guid>
		<description>Hi,

About the tests with the Theories, I can&#039;t use it to do what you are saying:

The &#039;testTheNewTheoriesStuff&#039; Theory is then executed with each of the values defined in the values array decorated with the @DataPoints annotation.

When I use an array of Objects, the @Test/@Theory will expect an array as parameter in the method....So if I have a array of int as DataPoints, I must use an array of int as parameter in the test..... :/</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>About the tests with the Theories, I can&#8217;t use it to do what you are saying:</p>
<p>The &#8216;testTheNewTheoriesStuff&#8217; Theory is then executed with each of the values defined in the values array decorated with the @DataPoints annotation.</p>
<p>When I use an array of Objects, the @Test/@Theory will expect an array as parameter in the method&#8230;.So if I have a array of int as DataPoints, I must use an array of int as parameter in the test&#8230;.. :/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sudhanshu</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-24156</link>
		<dc:creator>sudhanshu</dc:creator>
		<pubDate>Tue, 13 Oct 2009 03:12:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-24156</guid>
		<description>Sorry this is not meant for lexi , this is for Sai</description>
		<content:encoded><![CDATA[<p>Sorry this is not meant for lexi , this is for Sai</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sudhanshu</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-24155</link>
		<dc:creator>sudhanshu</dc:creator>
		<pubDate>Tue, 13 Oct 2009 03:11:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-24155</guid>
		<description>Hi lexi , 

Can you please let us know how your test method are running without error.
I have used @RunWith(Theories.class) but my test methods are expecting @Theory , if i will annotate with @Test then i am getting errors that test methods should not have any arguments</description>
		<content:encoded><![CDATA[<p>Hi lexi , </p>
<p>Can you please let us know how your test method are running without error.<br />
I have used @RunWith(Theories.class) but my test methods are expecting @Theory , if i will annotate with @Test then i am getting errors that test methods should not have any arguments</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lexi</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-8467</link>
		<dc:creator>lexi</dc:creator>
		<pubDate>Wed, 11 Feb 2009 06:26:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-8467</guid>
		<description>Theories are my favourite feature too. I like it because it makes it possible to define tests for common properties of classes.

http://blog.bader-jene.de/?p=30</description>
		<content:encoded><![CDATA[<p>Theories are my favourite feature too. I like it because it makes it possible to define tests for common properties of classes.</p>
<p><a href="http://blog.bader-jene.de/?p=30" rel="nofollow">http://blog.bader-jene.de/?p=30</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sai</title>
		<link>http://www.markhneedham.com/blog/2008/12/12/junit-theories-first-thoughts/comment-page-1/#comment-2957</link>
		<dc:creator>Sai</dc:creator>
		<pubDate>Tue, 13 Jan 2009 12:23:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=730#comment-2957</guid>
		<description>Thanks. 

I wrote a test program using @RunWith(Theories.class) and had few static public variables that act has @Datapoint. I had some parameterized methods and used @Test (instead of @Theory) annotation. 

@RunWith(Theories.class)
public class TestCalculatorUsingDataPoints {

    Calculator calculator = null;
    
    @DataPoint
    public static int first_number = 10;
    
    @DataPoint
    public static int second_number = 20;

@Before
    public void setUp() {
        calculator = new Calculator();
    }

    @After
    public void tearDown() {
        calculator = null;
    }
    
    @Test
    public void add(int number1, int number2) {
        int actualResult = calculator.add(number1, number2);
        //assertEquals(expectedResult, actualResult);
        int expectedResult = number1 + number2;
        System.out.println(&quot;add &quot; + number1 + &quot; &quot; + number2);
        assertThat(actualResult, is(expectedResult));
    }
}

JUnit did not throw any error that @Theory should be used. JUnit recognized the @Test methods and call the same method with each datapoint. 

Result:
add 10 10
add 10 20
add 20 10
add 20 20


Isn&#039;t weird?</description>
		<content:encoded><![CDATA[<p>Thanks. </p>
<p>I wrote a test program using @RunWith(Theories.class) and had few static public variables that act has @Datapoint. I had some parameterized methods and used @Test (instead of @Theory) annotation. </p>
<p>@RunWith(Theories.class)<br />
public class TestCalculatorUsingDataPoints {</p>
<p>    Calculator calculator = null;</p>
<p>    @DataPoint<br />
    public static int first_number = 10;</p>
<p>    @DataPoint<br />
    public static int second_number = 20;</p>
<p>@Before<br />
    public void setUp() {<br />
        calculator = new Calculator();<br />
    }</p>
<p>    @After<br />
    public void tearDown() {<br />
        calculator = null;<br />
    }</p>
<p>    @Test<br />
    public void add(int number1, int number2) {<br />
        int actualResult = calculator.add(number1, number2);<br />
        //assertEquals(expectedResult, actualResult);<br />
        int expectedResult = number1 + number2;<br />
        System.out.println(&#8220;add &#8221; + number1 + &#8221; &#8221; + number2);<br />
        assertThat(actualResult, is(expectedResult));<br />
    }<br />
}</p>
<p>JUnit did not throw any error that @Theory should be used. JUnit recognized the @Test methods and call the same method with each datapoint. </p>
<p>Result:<br />
add 10 10<br />
add 10 20<br />
add 20 10<br />
add 20 20</p>
<p>Isn&#8217;t weird?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

