<?xml version="1.0" encoding="UTF-8"?>
<chapter id="test" xreflabel="test">
    <?dbhtml filename="test.html"?>
    <chapterinfo>
        <keywordset>
            <keyword>test</keyword>
            <keyword>unit</keyword>
          <keyword>CDK</keyword>
		<keyword>Guide</keyword>
        </keywordset>
    </chapterinfo>
    <title>Generating unit tests</title>
    <para>
      Unit testing is a method of testing that verifies the individual units of source code are working properly. 
      A unit is the smallest testable part of an application, method for example.
      </para>
      <para>
      The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. 
      Unit tests find problems early in the development cycle and allow you 
      to perform code refactoring at a later date, and make sure the module still works correctly.
      By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.
      </para>
      <para>
      Unit testing provides a sort of living documentation of the system. You could learn unit functionality
      by looking at the unit test and get a basic understanding of the unit API.
    </para>
    <note>
		<title>Note:</title>
		<para>
			Unit testing cannot be expected to catch every error in the program. 
			It only tests the functionality of the units themselves. 
			Therefore it is more effective if  the other software testing activities
			are used in conjunction with unit tests.
		</para>
	</note>
	<para>
		Unit tests generated by CDK check all the properties of the component, resources availability,
		and perform render test view.  
	</para>
	<para>
		In order to add unit tests to the project you should 
		take the following steps:
	</para>
	<itemizedlist>
		<listitem>
			<para>
				proceed to the <property>inputDate/src/main/config/component</property> directory,
				open the <property>inputDate.xml</property> file
			</para>
		</listitem>
		<listitem>
			<para>
				add the <emphasis role="bold"><property>&lt;test&gt;</property></emphasis> element nested to
				<emphasis role="bold"><property>&lt;component&gt;</property></emphasis> in order to generate
				unit test for the <property>UIInputDate</property> class
			</para>
			    <programlisting role="XML"><![CDATA[...
<test>
	<classname>org.richfaces.component.html.HtmlInputDateComponentTest</classname>
	<superclassname>org.ajax4jsf.tests.AbstractAjax4JsfTestCase</superclassname> 
</test>
...]]></programlisting>
		</listitem>
				<listitem>
			<para>
				add the <emphasis role="bold"><property>&lt;test /&gt;</property></emphasis> element nested to
				<emphasis role="bold"><property>&lt;tag&gt;</property></emphasis> in order to generate
				unit test for the <property>InputDateTag</property> class
			</para>
			    <programlisting role="XML"><![CDATA[...
<tag>
	<name>inputDate</name>
	<classname>org.mycompany.taglib.InputDateTag</classname>
	<superclass>org.ajax4jsf.webapp.taglib.HtmlComponentTagBase</superclass>
	<test/>
</tag>
...]]></programlisting>
		</listitem>
		<listitem>
			<para>
				proceed to the <property>inputDate</property> directory,
				and add new execution with the <property>generate-tests</property> goal to <property>pom.xml</property>
			</para>
						    <programlisting role="XML"><![CDATA[...
<execution>
	<id>generate-test-sources</id>
	<phase>generate-test-sources</phase>
	<goals>
		<goal>generate-tests</goal>
	</goals>
</execution>
...]]></programlisting>
		</listitem>
				<listitem>
			<para>
				launch the following command in the <property>inputDate</property> directory
			</para>
			<programlisting role="XML"><![CDATA[mvn clean install]]></programlisting>
		</listitem>
	</itemizedlist>
	<para>
		 If all the tests have been run successfully, the &quot;BUILD SUCCESSFUL&quot; message will appeared.
	</para>
	<para>
		You could also find detailed tests information in the <property>surefire reports</property> placed in the 
		<property>inputDate/target/surefire-reports</property> directory.  
	</para>
</chapter>