一、ANT任务之Junit:
学习ANT其实主要是学习ANT的task,ANT众多task中有一个Testing Tasks,它下面有两个任务:Junit和JunitReport,主要用来进行单元测试及生成单元测试报告。
| Testing Tasks |
|---|
| Task Name | Description |
|---|---|
| Junit |
Runs tests from the Junit testing framework. This task has been tested with JUnit 3.0 up to JUnit 3.7; it won't work with versions prior to JUnit 3.0. |
| JunitReport |
Merges the individual XML files generated by the Junit task and applies a stylesheet on the resulting merged document to provide a browsable report of the testcases results. |
官方网址:http://ant.apache.org/manual/index.html
<junit>下面可以包含其它元素,例如:
1、<test>:运行单个TestCase
2、<batchtest>:运行多个TestCase
3、<formatter>:定义测试结果输出格式
还有很多,详细可以参考官方文档。
二、项目实例:
由于ant安装比较得简单,网上一搜一大把且现在ecplise基本都带ant,所以本文并未说明如何搭建ant环境。
另外,在eclipse中可以通过:window->show view 来调出Ant视图
1、目录结构如下:
2、SimpleCalculation类代码如下:
1 package com.glen.he; 2 3 public class SimpleCalculation { 4 public int Add(int a,int b){ 5 return (a+b); 6 } 7 8 }