<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hwang7</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hwang7"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Hwang7"/>
	<updated>2026-09-18T14:20:18Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_1_103&amp;diff=19114</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 1 103</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_1_103&amp;diff=19114"/>
		<updated>2009-09-12T21:02:16Z</updated>

		<summary type="html">&lt;p&gt;Hwang7: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' Writing Effective Junit Test Cases '''&lt;br /&gt;
&lt;br /&gt;
This article introduces the best practice a developer should follow in writing ''JUnit'' test cases for Java programming.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
Readers are assumed to be familiar with the following terms/names and their concepts:&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit Testing] - A verification process run by a developer on the smallest testable parts of an application. &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Test_case Test case] - A process generates a set of conditions and variables by which a developer can tell if a piece of software works correctly.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/JUnit JUnit] - A unit testing framework for programming in Java.&lt;br /&gt;
&lt;br /&gt;
== Criteria For Effective Unit Testing ==&lt;br /&gt;
&lt;br /&gt;
* Design - It's &amp;quot;Hard to design testable code&amp;quot;. &amp;quot;However, testable code often is better designed&amp;quot; [http://bradwilson.typepad.com/presentations/effective-unit-testing.pdf [1]]&lt;br /&gt;
* Documentation - Good documentation could prevent oversight, increase transparency, and facilitate knowledge transfer in the future.[http://www.exforsys.com/tutorials/testing/unit-testing.html [2]]&lt;br /&gt;
* Good coverage,&lt;br /&gt;
: What should be covered in each run of the test:&lt;br /&gt;
# UI - All screen elements, spelling, fonts, and sizes of all the “labels” or text. May not be applicable to JUnit since automation may be improbable here.&lt;br /&gt;
# Every line of code should at least be executed once. &lt;br /&gt;
# Every condition in case of “conditional statements” should be met at least once.&lt;br /&gt;
# Every path of all possible ones should be gone through at least once.&lt;br /&gt;
# Boundaries - The input parameters should be tested with conditions at the lower and/or upper limits such as too large or too small. Overflow condition should also be tested.&lt;br /&gt;
# Every error message/exception handling should be tested&lt;br /&gt;
# All validations are being performed, correctly.&lt;br /&gt;
# All possible setup configurations should be tested.&lt;br /&gt;
* Avoid redundant tests which may give wrong impression of the scale of the bugs and fixes.&lt;br /&gt;
* Easy for automation, which should be implied by JUnit. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Cases Specific to JUnit Test Cases ==&lt;br /&gt;
In theory, there shouldn't be anything special regarding to effective unit testing in JUnit compared to any other testing framework. A couple of good resources for designing tests specific in JUnit is the [http://junit.sourceforge.net/doc/faq/faq.htm JUnit FAQ], and the book &amp;quot;Pragmatic Unit Testing in Java with JUnit&amp;quot;.&lt;br /&gt;
*A simple test&lt;br /&gt;
: Create a class:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    package myPackageToBeTested;&lt;br /&gt;
    import org.junit.*;&lt;br /&gt;
    import static org.junit.Assert.*;&lt;br /&gt;
    import java.util.*;&lt;br /&gt;
    public class SimpleTest {&lt;br /&gt;
      	  &lt;br /&gt;
        //a test method (annotated with @Test) using asserts:&lt;br /&gt;
        @Test&lt;br /&gt;
        public void test1plus1() {&lt;br /&gt;
            assertEquals(&amp;quot;1+1=2&amp;quot;, 2, 1+1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;	 &lt;br /&gt;
* A test suite&lt;br /&gt;
: Add a suite() method to the above ''simple test'' example to include all of your test methods:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
        ...&lt;br /&gt;
        public static junit.framework.Test suite() {&lt;br /&gt;
            return new junit.framework.JUnit4TestAdapter(SimpleTest.class);&lt;br /&gt;
        }&lt;br /&gt;
        ...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* A test template&lt;br /&gt;
: This sample test template contains setUp() and tearDown() methods to initialize and release the object(s) being tested&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    import org.junit.*;&lt;br /&gt;
    import static org.junit.Assert.*;&lt;br /&gt;
&lt;br /&gt;
    public class TemplateTest {&lt;br /&gt;
 &lt;br /&gt;
        // Sets up the test fixture. &lt;br /&gt;
        @Before&lt;br /&gt;
        public void setUp() {&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        //Tears down the test fixture. &lt;br /&gt;
        @After&lt;br /&gt;
        public void tearDown() {&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        //a test method (annotated with @Test) using asserts:&lt;br /&gt;
        @Test&lt;br /&gt;
        public void test1plus1() {&lt;br /&gt;
            assertEquals(&amp;quot;1+1=2&amp;quot;, 2, 1+1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static junit.framework.Test suite() {&lt;br /&gt;
            return new junit.framework.JUnit4TestAdapter(TemplateTest.class);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# [http://bradwilson.typepad.com/presentations/effective-unit-testing.pdf effective unit testing]&lt;br /&gt;
# [http://www.exforsys.com/tutorials/testing/unit-testing.html Unit Testing: Why? What? &amp;amp; How?]&lt;br /&gt;
# [http://junit.sourceforge.net/doc/faq/faq.htm JUnit FAQ]&lt;br /&gt;
# White Box Testing Techniques - NCSU:CSC 510 Software Engineering (Lecture 8)&lt;br /&gt;
# Pragmatic Unit Testing in Java with JUnit (ISBN:9780974514017)&lt;/div&gt;</summary>
		<author><name>Hwang7</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_1_103&amp;diff=19113</id>
		<title>CSC/ECE 517 Fall 2009/wiki1a 1 103</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki1a_1_103&amp;diff=19113"/>
		<updated>2009-09-12T21:02:04Z</updated>

		<summary type="html">&lt;p&gt;Hwang7: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''' Writing Effective Junit Test Cases '''&lt;br /&gt;
&lt;br /&gt;
This article introduces the best practice a developer should follow in writing ''JUnit'' test cases for Java programming.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
Readers are assumed to be familiar with the following terms/names and their conceptdsc:&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Unit_testing Unit Testing] - A verification process run by a developer on the smallest testable parts of an application. &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Test_case Test case] - A process generates a set of conditions and variables by which a developer can tell if a piece of software works correctly.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/JUnit JUnit] - A unit testing framework for programming in Java.&lt;br /&gt;
&lt;br /&gt;
== Criteria For Effective Unit Testing ==&lt;br /&gt;
&lt;br /&gt;
* Design - It's &amp;quot;Hard to design testable code&amp;quot;. &amp;quot;However, testable code often is better designed&amp;quot; [http://bradwilson.typepad.com/presentations/effective-unit-testing.pdf [1]]&lt;br /&gt;
* Documentation - Good documentation could prevent oversight, increase transparency, and facilitate knowledge transfer in the future.[http://www.exforsys.com/tutorials/testing/unit-testing.html [2]]&lt;br /&gt;
* Good coverage,&lt;br /&gt;
: What should be covered in each run of the test:&lt;br /&gt;
# UI - All screen elements, spelling, fonts, and sizes of all the “labels” or text. May not be applicable to JUnit since automation may be improbable here.&lt;br /&gt;
# Every line of code should at least be executed once. &lt;br /&gt;
# Every condition in case of “conditional statements” should be met at least once.&lt;br /&gt;
# Every path of all possible ones should be gone through at least once.&lt;br /&gt;
# Boundaries - The input parameters should be tested with conditions at the lower and/or upper limits such as too large or too small. Overflow condition should also be tested.&lt;br /&gt;
# Every error message/exception handling should be tested&lt;br /&gt;
# All validations are being performed, correctly.&lt;br /&gt;
# All possible setup configurations should be tested.&lt;br /&gt;
* Avoid redundant tests which may give wrong impression of the scale of the bugs and fixes.&lt;br /&gt;
* Easy for automation, which should be implied by JUnit. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Cases Specific to JUnit Test Cases ==&lt;br /&gt;
In theory, there shouldn't be anything special regarding to effective unit testing in JUnit compared to any other testing framework. A couple of good resources for designing tests specific in JUnit is the [http://junit.sourceforge.net/doc/faq/faq.htm JUnit FAQ], and the book &amp;quot;Pragmatic Unit Testing in Java with JUnit&amp;quot;.&lt;br /&gt;
*A simple test&lt;br /&gt;
: Create a class:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    package myPackageToBeTested;&lt;br /&gt;
    import org.junit.*;&lt;br /&gt;
    import static org.junit.Assert.*;&lt;br /&gt;
    import java.util.*;&lt;br /&gt;
    public class SimpleTest {&lt;br /&gt;
      	  &lt;br /&gt;
        //a test method (annotated with @Test) using asserts:&lt;br /&gt;
        @Test&lt;br /&gt;
        public void test1plus1() {&lt;br /&gt;
            assertEquals(&amp;quot;1+1=2&amp;quot;, 2, 1+1);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;	 &lt;br /&gt;
* A test suite&lt;br /&gt;
: Add a suite() method to the above ''simple test'' example to include all of your test methods:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
        ...&lt;br /&gt;
        public static junit.framework.Test suite() {&lt;br /&gt;
            return new junit.framework.JUnit4TestAdapter(SimpleTest.class);&lt;br /&gt;
        }&lt;br /&gt;
        ...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* A test template&lt;br /&gt;
: This sample test template contains setUp() and tearDown() methods to initialize and release the object(s) being tested&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    import org.junit.*;&lt;br /&gt;
    import static org.junit.Assert.*;&lt;br /&gt;
&lt;br /&gt;
    public class TemplateTest {&lt;br /&gt;
 &lt;br /&gt;
        // Sets up the test fixture. &lt;br /&gt;
        @Before&lt;br /&gt;
        public void setUp() {&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        //Tears down the test fixture. &lt;br /&gt;
        @After&lt;br /&gt;
        public void tearDown() {&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        //a test method (annotated with @Test) using asserts:&lt;br /&gt;
        @Test&lt;br /&gt;
        public void test1plus1() {&lt;br /&gt;
            assertEquals(&amp;quot;1+1=2&amp;quot;, 2, 1+1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        public static junit.framework.Test suite() {&lt;br /&gt;
            return new junit.framework.JUnit4TestAdapter(TemplateTest.class);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
# [http://bradwilson.typepad.com/presentations/effective-unit-testing.pdf effective unit testing]&lt;br /&gt;
# [http://www.exforsys.com/tutorials/testing/unit-testing.html Unit Testing: Why? What? &amp;amp; How?]&lt;br /&gt;
# [http://junit.sourceforge.net/doc/faq/faq.htm JUnit FAQ]&lt;br /&gt;
# White Box Testing Techniques - NCSU:CSC 510 Software Engineering (Lecture 8)&lt;br /&gt;
# Pragmatic Unit Testing in Java with JUnit (ISBN:9780974514017)&lt;/div&gt;</summary>
		<author><name>Hwang7</name></author>
	</entry>
</feed>