<?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"
	>
<channel>
	<title>Comments on: JUnit 4 in 60 Seconds</title>
	<atom:link href="http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/</link>
	<description>Tech, Internet, Engineering and Life Blog</description>
	<pubDate>Mon, 01 Dec 2008 23:23:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Dosha Kenkan</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-126</link>
		<dc:creator>Dosha Kenkan</dc:creator>
		<pubDate>Mon, 10 Nov 2008 18:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-126</guid>
		<description>very helpful, thanks</description>
		<content:encoded><![CDATA[<p>very helpful, thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aparna</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-124</link>
		<dc:creator>Aparna</dc:creator>
		<pubDate>Fri, 07 Nov 2008 15:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-124</guid>
		<description>Thank you for this fantastic short introduction to JUnit 4.</description>
		<content:encoded><![CDATA[<p>Thank you for this fantastic short introduction to JUnit 4.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mattias</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-123</link>
		<dc:creator>Mattias</dc:creator>
		<pubDate>Wed, 05 Nov 2008 10:51:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-123</guid>
		<description>Thanks for a great (and quick) introduction to JUnit4. This is more or less the only information that is needed for a quick start.
A short description and an example. GREAT!</description>
		<content:encoded><![CDATA[<p>Thanks for a great (and quick) introduction to JUnit4. This is more or less the only information that is needed for a quick start.<br />
A short description and an example. GREAT!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arvids</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-122</link>
		<dc:creator>Arvids</dc:creator>
		<pubDate>Fri, 31 Oct 2008 16:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-122</guid>
		<description>Great one!</description>
		<content:encoded><![CDATA[<p>Great one!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sk_svenska</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-120</link>
		<dc:creator>sk_svenska</dc:creator>
		<pubDate>Thu, 30 Oct 2008 14:43:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-120</guid>
		<description>Good?
Simple and easy?(*^__^*)</description>
		<content:encoded><![CDATA[<p>Good?<br />
Simple and easy?(*^__^*)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ye Fu</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-119</link>
		<dc:creator>Ye Fu</dc:creator>
		<pubDate>Wed, 29 Oct 2008 09:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-119</guid>
		<description>Very nice . Thanks</description>
		<content:encoded><![CDATA[<p>Very nice . Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cha</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-114</link>
		<dc:creator>cha</dc:creator>
		<pubDate>Mon, 20 Oct 2008 18:29:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-114</guid>
		<description>Nice answer. It's very useful to me.

Thanks so much !</description>
		<content:encoded><![CDATA[<p>Nice answer. It&#8217;s very useful to me.</p>
<p>Thanks so much !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abdullah Cetin CAVDAR</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-109</link>
		<dc:creator>Abdullah Cetin CAVDAR</dc:creator>
		<pubDate>Thu, 09 Oct 2008 21:20:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-109</guid>
		<description>Test cases are not run in any order and you cannot guarantee to run them in some specific order.

You don't need them run in any order and you must not infact. Because test case must be independent. It means, it must run successfully without dependent (data, condition etc.) of any other test case(s). This is an important feature of test cases. 

So, you have to setup your test case's running condition before it runs, you check or test something (using asserts) and you leave your environment in its state before the setting up process. The setUp() and tearDown() methods (naming convention before the JUnit 4.x) is generally used for this purpose. Because they run before and after each test case. They are annotated as @Before and @After in JUnit 4.X as we mentioned. 

In your example, you can create a user in a method annotated with @Before and you delete that user in in another method annotated with @After. Therefore, you guarantee that you have a user that you exactly know in your system to test your other methods. It can be something like that:

@Before
public void initializeSystem() {
// user: id, name, surname
this.user = userDAO.createUser(1, "Foo", "Bar");
}

@Test
public void getUserById() {
User newUser = userDAO.findUserById(1);
assertEquals(this.user.getName(), newUser.getName());
assertEquals(this.user.getSurname(), newUser.getSurname());
} 

@After
public void cleanSystemState() {
userDAO.deleteUser(this.user);
}

For the above example, you have to guarantee that createUser() and deleteUser() methods are running correctly of course. 

I hope, it gives the general approach of independent unit testing. Creating such an environment is not easy I know. However, when we try to test our system as isolated and independent as possible, we not only testing our system, we are improving our overall architecture without noticing it. So, we have well-defined, fully tested, ready to use components and interfaces. I think, this is what we try to achieve. :D</description>
		<content:encoded><![CDATA[<p>Test cases are not run in any order and you cannot guarantee to run them in some specific order.</p>
<p>You don&#8217;t need them run in any order and you must not infact. Because test case must be independent. It means, it must run successfully without dependent (data, condition etc.) of any other test case(s). This is an important feature of test cases. </p>
<p>So, you have to setup your test case&#8217;s running condition before it runs, you check or test something (using asserts) and you leave your environment in its state before the setting up process. The setUp() and tearDown() methods (naming convention before the JUnit 4.x) is generally used for this purpose. Because they run before and after each test case. They are annotated as @Before and @After in JUnit 4.X as we mentioned. </p>
<p>In your example, you can create a user in a method annotated with @Before and you delete that user in in another method annotated with @After. Therefore, you guarantee that you have a user that you exactly know in your system to test your other methods. It can be something like that:</p>
<p>@Before<br />
public void initializeSystem() {<br />
// user: id, name, surname<br />
this.user = userDAO.createUser(1, &#8220;Foo&#8221;, &#8220;Bar&#8221;);<br />
}</p>
<p>@Test<br />
public void getUserById() {<br />
User newUser = userDAO.findUserById(1);<br />
assertEquals(this.user.getName(), newUser.getName());<br />
assertEquals(this.user.getSurname(), newUser.getSurname());<br />
} </p>
<p>@After<br />
public void cleanSystemState() {<br />
userDAO.deleteUser(this.user);<br />
}</p>
<p>For the above example, you have to guarantee that createUser() and deleteUser() methods are running correctly of course. </p>
<p>I hope, it gives the general approach of independent unit testing. Creating such an environment is not easy I know. However, when we try to test our system as isolated and independent as possible, we not only testing our system, we are improving our overall architecture without noticing it. So, we have well-defined, fully tested, ready to use components and interfaces. I think, this is what we try to achieve. <img src='http://www.cavdar.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cha</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-107</link>
		<dc:creator>cha</dc:creator>
		<pubDate>Wed, 08 Oct 2008 18:49:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-107</guid>
		<description>Hi,

I have a question that do the test cases run in order or not? 

Ex: I have test class includes 3 cases (testMethod1, testMethod2, testMethod3)

When running, I see sometimes they run in order 

testMethod1
testMethod2
testMethod3

but sometimes is not (2,1,3 or 3,2,1 ...). Since I'm using a data sharing between them so that I must assure they will be run in order. My real case is :

testCreateUser() --&#62; always make sure this case will run firstly

These case will be fail or error if testCreateUser() did not run before:

testGetUserByID()  
testEditUser()
...

Anyone can help me to show how to make them run in order always? I'm using JUnit4.x

Thanks a lot.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have a question that do the test cases run in order or not? </p>
<p>Ex: I have test class includes 3 cases (testMethod1, testMethod2, testMethod3)</p>
<p>When running, I see sometimes they run in order </p>
<p>testMethod1<br />
testMethod2<br />
testMethod3</p>
<p>but sometimes is not (2,1,3 or 3,2,1 &#8230;). Since I&#8217;m using a data sharing between them so that I must assure they will be run in order. My real case is :</p>
<p>testCreateUser() &#8211;&gt; always make sure this case will run firstly</p>
<p>These case will be fail or error if testCreateUser() did not run before:</p>
<p>testGetUserByID()<br />
testEditUser()<br />
&#8230;</p>
<p>Anyone can help me to show how to make them run in order always? I&#8217;m using JUnit4.x</p>
<p>Thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mighty Chip</title>
		<link>http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/#comment-103</link>
		<dc:creator>Mighty Chip</dc:creator>
		<pubDate>Thu, 02 Oct 2008 13:46:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.cavdar.net/?p=97#comment-103</guid>
		<description>Awesome tutorial!!  Thanks so much!  :) Makes moving up to 4.x a snap!</description>
		<content:encoded><![CDATA[<p>Awesome tutorial!!  Thanks so much!  <img src='http://www.cavdar.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Makes moving up to 4.x a snap!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
