<?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>Java and Me &#187; JUnit</title>
	<atom:link href="http://rpktech.com/category/junit/feed/" rel="self" type="application/rss+xml" />
	<link>http://rpktech.com</link>
	<description>An Interesting Journey</description>
	<lastBuildDate>Sun, 22 Nov 2015 11:01:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>JUnit Introduction</title>
		<link>http://rpktech.com/2015/02/02/junit_introduction/</link>
		<comments>http://rpktech.com/2015/02/02/junit_introduction/#comments</comments>
		<pubDate>Mon, 02 Feb 2015 13:09:21 +0000</pubDate>
		<dc:creator><![CDATA[Rahul Kulshreshtha]]></dc:creator>
				<category><![CDATA[JUnit]]></category>

		<guid isPermaLink="false">http://rpktech.com/?p=9</guid>
		<description><![CDATA[JUnit is used for unit testing of Java applications. JUnit and TestNG are two popular unit testing frameworks. In this tutorial I will explore JUnit only. There are two popular version of JUnit &#8211; JUnit 3 and JUnit 4. Below table]]></description>
				<content:encoded><![CDATA[<p>JUnit is used for unit testing of Java applications. JUnit and TestNG are two popular unit testing frameworks. In this tutorial I will explore JUnit only.</p>
<p>There are two popular version of JUnit &#8211; JUnit 3 and JUnit 4. Below table shows few important differences in these versions . Apart from this there is one more important difference that from JUnit 4.7 parallel execution of JUnit test cases is supported.</p>
<p><a href="http://rpktech.com/wp-content/uploads/2015/02/JUnit3-Junit4.png" target="_blank"><img class="aligncenter wp-image-17 size-full" src="http://rpktech.com/wp-content/uploads/2015/02/JUnit3-Junit4.png" alt="JUnit3-Junit4" width="762" height="374" /></a></p>
<p>&nbsp;</p>
<p><strong>JUnit 3.x Sample</strong></p>
<pre class="brush: java; title: ; notranslate">import junit.framework.*;
public class MoneyTest extends TestCase {
	private Money f12CHF;			// fixtures
	private Money f14CHF;

	protected void setUp() {		// create the test data
		f12CHF = new Money(12, &quot;CHF&quot;);
		f14CHF = new Money(14, &quot;CHF&quot;);
	}
   void testAdd() {				// create the test data
		Money expected = new Money(26, “CHF”);
		assertEquals(“amount not equal”,
                     expected,f12CHF.add(f14CHF);
	}
	...
}
</pre>
<p><strong>JUnit 4.x Sample</strong></p>
<pre class="brush: java; title: ; notranslate">
import junit.framework.*;
import org.junit.*;
import static org.junit.Assert.*;
public class MoneyTest &lt;del&gt;extends TestCase&lt;/del&gt; {
	private Money f12CHF;
	private Money f14CHF;

	@Before
        public void setUp() // setup, teardown function names are not mandatory now as we have annotations now
        {
		f12CHF = new Money(12, &quot;CHF&quot;);    // - the fixture
		f14CHF = new Money(14, &quot;CHF&quot;);
	}
	@Test
        public void testAdd() // create the test data
        {
		Money expected = new Money(26, “CHF”);
		assertEquals(“amount not equal”,
                     expected,f12CHF.add(f14CHF));
	}
	...
}

</pre>
<p><strong>Following changes were happened in JUnit 4.x</strong></p>
<ol>
<li>No need to start test method name with prefix &#8220;test&#8221;.</li>
<li>@BeforeClass and @AfterClass were introduced
<ol>
<li>@BeforeClass method &#8211; executes <strong>only once</strong>; before the first test method</li>
<li>@AfterClass method &#8211; executes <strong>only once</strong>; after the last test method</li>
</ol>
</li>
<li>Instead of setup and tearDown now JUnit 4 has @Before and @After annotations.
<ol>
<li>@Before method &#8211; executes <strong>every time; </strong>before the test method.</li>
<li>@After method &#8211; executes <strong>every time; </strong>after the test method.</li>
</ol>
</li>
<li>@Ignore was introduced to skip a test case while running.</li>
<li>&#8220;expected&#8221; was introduced to tell JUnitRunner that what exception we are expecting. Example : @Test(expected=ArithmeticException.class)</li>
<li>&#8220;timeout&#8221; was introduced to put a time limit on a testcase. If test does not complete in that time limit, an exception will raise with message &#8220;test timed out after xxx milliseconds&#8221;</li>
</ol>
<p>Next posts will show the working examples with these annotations.</p>
<p><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Frpktech.com%2F2015%2F02%2F02%2Fjunit_introduction%2F&amp;linkname=JUnit%20Introduction" title="Facebook" rel="nofollow" target="_blank"></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Frpktech.com%2F2015%2F02%2F02%2Fjunit_introduction%2F&amp;linkname=JUnit%20Introduction" title="Twitter" rel="nofollow" target="_blank"></a><a class="a2a_button_google_plus" href="http://www.addtoany.com/add_to/google_plus?linkurl=http%3A%2F%2Frpktech.com%2F2015%2F02%2F02%2Fjunit_introduction%2F&amp;linkname=JUnit%20Introduction" title="Google+" rel="nofollow" target="_blank"></a><a class="a2a_dd a2a_target addtoany_share_save" href="https://www.addtoany.com/share#url=http%3A%2F%2Frpktech.com%2F2015%2F02%2F02%2Fjunit_introduction%2F&amp;title=JUnit%20Introduction" id="wpa2a_2"></a></p>]]></content:encoded>
			<wfw:commentRss>http://rpktech.com/2015/02/02/junit_introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
