ANT actual articles (1)
Amender: Huang Kai
E_mail: hk_sz@163.com
Forehead
Since the company is now undergoing the unit test case, the evacuation understands Ant and Junit technology. The following is the collection of the director of the people (considering the summary of my idea, maybe not fully express the original author I think, I will listen out all the articles of the article or books in the reference. Everyone has time to see the original text).
If you don't understand the ANT part of the parameters, please refer to the "Ant Theory" series or Ant comes with documents.
table of Contents
First, ANT use example
1.1 Copt Task via ANT submitted the recently updated file (according to the system time) file in the current directory to the specified directory
1.2 Develop Java programs with ANT
1.3 ANT combined with JUnit for software automatic test
1.4 ANT development and deployment web applications
1.5 ANT Packaging (JAR) application
1.6 ANT development EJB application
reference
First, ANT use example
1.3 ANT combined with JUnit for software automatic test
1> The automatic process of starting basic compilation and testing with ANT binding JUnit is as follows:
★ Execute JUnit test
★ Capture the test results, record the results to the XML file or other format
★ Translate results into test report based on XSL format
★ Translate this report to HTML format
★ Send a report by email
Once the capture result, you can use the XML formatter to run the number of faults and errors for each test suite, along with the execution time of the test suite with the package and class name. For each test suite, the following information is captured:
☆ Name of the test case
☆ Duration of execution
☆ Type of fault or error (if applicable)
☆ Any fault or error details
2> Directory structure of this instance:
D: / car home directory
/ SRC source program directory
/ Classes compiled Class file directory
/ ETC Other
/ XSL XSL file directory
First create a CAR directory, SRC subdirectories, and copy the junit-noframes.xsl file from% ANT_HOME% / ETC to the D: / car / etc / xsl subdirectory.
3> Download from http://download.sourceforge.net/junit/junit3.8.zip, unzip to the D disk, copy the junit.jar file under its directory to the% Ant_home% / lib directory.
4> New Car.java and TestCar.java files in the src subdirectory.
The content of car.java is as follows: // The class that will be tested
Public Class Car
{
Public int getWheels ()
{
Return 3;
}
}
The contents of TestCar.java are as follows:
// Class to execute the test
Import junit.framework. *;
Public Class Testcar Extends Testcase
{
Protected int expectedwheels;
protected car mycar;
Public testcar (String name)
{
Super (Name);
}
protected void setup ()
{
EXPECTEDWHEELS = 4;
Mycar = new car ();
}
Public Static Test Suite ()
{
Return New TestSuite (TestCar.class);
}
Public void testGetwheels ()
{
Assertequals (expectedwheels, mycar.getwheels ());
}
5> in build.xml and build.properties files.
The buil.properties file content is as follows:
Src.dir = SRC
Build.dir = Classes
xsl.dir = etc / xsl
Report.dir = report
The building contents of the build.xml are as follows:
XML Version = "1.0"?>
javac>
target>
claspath>
fileset>
batchtest>
junit>
fileset>
junitreport>
target>
delete>
target>
provject>
6> Run Ant Junit in the D: / Car directory,
This generates JUnit-Noframes.html, Tests-TestSuits.xml, and TestCar.xml files in Car / Report, open JUnit-Noframes.html to view the results. Run an Ant Clean to restore the original.