Ant + JUnit testing automation

Source: Internet
Author: User

With the extensive promotion of refactoring technology and XP software engineering technology, the role of Unit Testing becomes more and more important in software engineering, A concise, easy-to-learn, widely applied, efficient, and stable unit test framework plays a vital role in the successful implementation of unit tests. In the Java programming statement environment, JUnit framework is an excellent testing framework that has been adopted and proven by most Java programmers, however, most programmers who have not tried the JUnit framework still find it difficult to learn how to compile unit tests for their own development projects, this may be because the user guide and documents attached to JUnit with framework code and utilities focus on interpreting the design methods and simple class usage instructions of the unit test framework, there is no detailed explanation of how to implement unit tests under a specific testing framework (JUnit) and how to update and maintain the existing unit test code during project development. Therefore, this document further supplements and describes the documents attached to JUnit, so that JUnit can be used by more development teams, this allows unit testing, refactoring, and XP technologies to be better promoted in more development teams.

This article will show the overall test method of ant + JUnit in code mode, generate the test report, and send it to the developer's mailbox

Place JUnit. jar in ant_home/lib and write the build. xml file.

Build. xml

<? XML version = 1.0 encoding = gb2312?>
<! -- Test the file and send the test report to the mailbox specified by the developer
By biggie (biggie@hns-soft.com) -->
<Project name = test default = build basedir =.>
<Property environment = ENV/>
<Property name = J2EE value = env. j2ee_home/>
<Property name = base. dir value =./>
<! -- Define test source file -->
<Property name = SRC value =$ {base. dir}/test/>
<! -- Define the output location -->
<Property name = classes value =$ {base. dir}/defaultroot/WEB-INF/classes/>
<! -- Define lib -->
<Property name = lib value =$ {base. dir}/lib/>
<! -- Define classpath -->
<Path id = appclasspath>
<Pathelement path =$ {java. Class. Path}/>
<Fileset dir =$ {base. dir}/defaultroot/WEB-INF/lib>
<Include name = *. Jar/>
</Fileset>
<Pathelement location =$ {base. dir}/defaultroot/WEB-INF/classes/>
<Pathelement location = D:/j2sdkee1.3.1/lib/J2EE. Jar/>
</Path>
<! -- Initialization -->
<Target name = init>
<Tstamp/>
<Mkdir dir =$ {classes}/>
</Target>
<Target name = compiletest depends = init>
<! -- Javac -->
<Javac srcdir =$ {SRC} destdir =$ {classes} DEBUG = off>
<Classpath refID = appclasspath/>
<Include name = **/*. Java/>
</Javac>
</Target>
<Target name = build depends = compiletest, run>
<Tstamp/>
<Exec executable =$ {base. dir}/email. Bat>
</Exec>
</Target>
<Target name = run>
<JUnit>
<Classpath refID = appclasspath/>
<Classpath>
<Pathelement location =$ {base. dir}/defaultroot/WEB-INF/classes/>
</Classpath>
<Formatter type = xml/>
<Test name = test. alltests haltonfailure = No OUTFILE = Result/>
</JUnit>
<Junitreport todir =./Report>
<Fileset dir =.>
<Include name = result. xml/>
</Fileset>
<Report format = noframes todir =./report/>
</Junitreport>
</Target>
</Project>

After the test report is generated, call the emai. BAT file to send an email. To achieve mass mailing, I use an application to send emails. You can also use ant to send emails directly. I will not talk about the introduction of related articles in the programmer's 7th issue.

This article provides an idea, you can also implement more powerful functions, distributed testing, overall testing, and so on.

Source: World computer it. icxo. com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.