JUnit单元测试
Junit4单元测试

Junit4单元测试Junit4单元测试第⼀部分⽤法1.1 常见功能典型配置:/*⽤于配置spring Boot中测试的环境*/@RunWith(SpringJUnit4ClassRunner.class)@SpringApplicationConfiguration(classes = MyBlogApplication.class)/* 开启事务,测试完成默认⾃动回滚,不会弄脏数据库 */@Transactionalpublic class WhoHaveWhatTagsMapperTest {@BeforeClasspublic static void beforeClass() {}@Beforepublic void setUp() throws Exception {}@Afterpublic void tearDown() throws Exception {}@Testpublic void insertWhoHaveWhatTags() throws Exception {}@Testpublic void selectBlogByTag() throws Exception {}@Testpublic void deleteWhoHaveWhatTags() throws Exception {}}@Test:把⼀个⽅法标记为测试⽅法两个属性:excepted;表⽰测试在执⾏中期望抛出的异常类型,如果不抛出,反⽽报错。
timeout:超时抛出异常。
单位毫秒@Test(timeout = 2000)@Test(expected = Exception.class)public void testFactorialException() throws Exception {new Math().factorial(-1);fail("factorial参数为负数没有抛出异常");}@Before:每⼀个测试⽅法执⾏前⾃动调⽤⼀次@After:每⼀个测试⽅法执⾏完⾃动调⽤⼀次@BeforeClass:所有测试⽅法执⾏前执⾏⼀次,在测试类还没有实例化就已经被加载,所以⽤static修饰@AfterClass:所有测试⽅法执⾏完执⾏⼀次,在测试类还没有实例化就已经被加载,所以⽤static修饰@Ignore:暂不执⾏该测试⽅法setup⽅法主要实现测试前的初始化⼯作teardown⽅法主要实现测试完成后垃圾回收⼯作!setup⽅法主要实现测试前的初始化⼯作,teardown⽅法主要实现测试完成后垃圾回收⼯作!测试⽅法的声明要求:名字可以随便取,没有任何限制,但是返回值必须为void,⽽且不能有任何参数。
android junit用法

android junit用法Android JUnit用法在Android开发中,JUnit是一种非常流行的测试框架。
使用JUnit可以方便地进行单元测试,在保证质量的同时也提高了开发效率。
在本文中,我们将逐步介绍如何使用JUnit进行Android开发中的测试。
一、JUnit介绍JUnit是一个使用Java编写的、开源的单元测试框架,它主要用于进行Java代码的单元测试。
JUnit提供了一种简单的方式来测试代码的正确性和性能,通过JUnit的测试可以检验程序的正确性是否符合预期,同时也可以帮助开发人员对代码进行重构,增加代码的可读性和可维护性。
JUnit的主要特点如下:1. JUnit是一个开源的、免费的单元测试框架,可在任何Java项目中使用。
2. JUnit提供了一系列的API,可以帮助开发人员快速构建测试用例。
3. JUnit通过执行测试用例(Test Case)来对代码进行测试,测试结果可视化,易于分析和优化。
四、JUnit的主要用途JUnit可以用于对Java程序进行单元测试。
通过JUnit测试,开发人员可以检验程序的正确性、边界和异常条件是否符合预期,可以帮助提高代码的质量和可维护性。
JUnit也可以用于对Android应用程序进行测试。
在Android开发中,JUnit 作为一个单元测试框架,可以对应用程序中的Java代码进行测试,并且可以与Android提供的测试框架结合使用,例如使用AndroidJUnitRunner来运行测试代码。
五、JUnit的使用方法1. 创建JUnit测试用例在Android Studio中创建JUnit测试用例非常简单。
只需要右键单击要测试的类,然后选择“New”-> “Test”-> “JUnit Test Case”即可。
在创建JUnit测试用例时,需要选择要测试的类和测试类型,例如:1. Method: 运行单个测试方法。
2. Class: 运行整个测试类。
JUnit 3 单元测试

Junit3单元测试笔记1.JUnit是每一个程序员必须掌握的技能之一。
2.使用JUnit的最佳实践:1)新建一个test的source folder,用于存放测试类源代码。
2)目标类与测试类应该处于同一个目录下,这样测试类中就不必导入源代码所在的包,因为他们处于同一目录下。
3)测试类命名规则:假如目标类是Calculator,那么测试类是CalculatorTest。
3.JUnit口号:keep the bar green to keep the code clean.保持横条是绿色的保持代码是整洁的4.我的名言:No reflection, No most frameworks.没有反射,没有太多的数据结构。
5.JUnit:单元测试不是为了证明您是对的,而是为了证明您的代码没有错误。
6.测试用例(Test Case)是单元测试的一个很重要的方面。
7.单元测试主要是用来判断程序运行的结果与自己期望的结果是否一致。
8.在JUnit3.8中,测试方法必须满足如下规则:1)方法必须是public。
2)方法必须是void。
没有返回值。
3)方法没有参数。
4)方法名必须是以Test开头。
9.测试用例之间要保持完全的独立性,不允许任何的依赖关系。
10.我们不能依赖与测试方法的执行顺序。
11.DRY(Don’t Repeat Yourself)。
不要重复你的代码。
在控制台中如下:每一个方法中都有:范例1:求int类型的数组中最大值。
除了使用JUnit方式进行测试之外,还可以在main方法中测试。
测试CalculatorTest,点击13.测试之前是什么状态,测试执行之后就应该是什么状态。
而不应该由于测试的原因导致状态发生了变化。
范例2:删除某一个目录的所有文件1)修改方法访问修饰符,将private修改为default或者是public。
(不推荐使用)。
2)使用反射在测试类中调用目标类的私有方法。
(推荐使用)。
(2).mybatis单元测试(junit测试)

(2).mybatis单元测试(junit测试)⼀、Junit使⽤步骤:1、创建测试⽬录,(src、测试⽬录是test)2、在测试⽬录test中创建与src中相同的包名3、为需要测试的类创建测试类,例如:UsersMapper,测试类是UsersMapperTest4、为被测试类(UsersMapper)中的需要测试的⽅法在测试类型创建相应的⽅法。
⽐如,需要测试findById⽅法,那么则测试类中创建findById⽅法,测试⽅法的要求a、不能有返回值、不能有参数b、需要只⽤@Test注解对该⽅法进⾏注解。
5、在测试⽅法中,使⽤断⾔对结果进⾏判断,assert,判断⼀。
单元测试1. 在项⽬下创建⼀个⽬录test,之后将test右键Mark Directory as(标记⽬录为)->测试源根2. 在test下创建类,类的包名与被测试类的包名⼀致,在被测试类后⾯加上Test,例如:ersMapper与ersMapperTest。
在测试⽅法前@Test,导⼊junit测试路径,点击确定即可,之后maven后台下载。
3. Mybatis的核⼼对象:SqlSessionFactoryBuilder , SqlSessionFactory , SqlSession。
(SqlSessionFactoryBuilder创建⼯⼚,⼀般只⽤⼀次。
SqlSessionFactory是⼯⼚,⼯⼚长期存在。
SqlSession例如是⼯⼚造的汽车,有时间期限,即使⽤完⼯⼚依旧存在。
) SqlSeessionFactoryBuilder⽤过即丢,可⽤来创建多个SqlSessionFactory实例,并提供多个build⽅法的重载来构建SqlSessionFactory. SqlSession(⼀般瞬时、短链接,也可以长连接,⽤完关闭)build(InputStream inputStream,String environment,Properties properties)build(Reader reader,String environment,Properties properties)build(Configuration config)配置信息以三种形式提供给 SqlessionFactoryld 的build ⽅法:InputStream(字节流) Reader (字符流) Configuration (类)读取XML⽂件构造⽅式:String CONFIG_FILE = "mybatis-config.xml";InputStream resourceAsStream = Resources.getResourceAsStream(CONFIG_FILE);SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder().build(resourceAsStream);//⾮静态成员,实例成员,成员变量,通过构造⽅法初始化。
junit+maven单元测试

junit+maven单元测试⼀、概念junit是⼀个专门测试的框架集合maven进⾏单元测试,可批量测试类中的⼤量⽅法是否符合预期⼆、作⽤:单元测试:测试的内容是类中的⽅法,每⼀个⽅法都是独⽴测试的。
⽅法是测试的基本单位。
三、使⽤⽅法1、pom内加⼊依赖<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope></dependency>2、在maven中src/test/java⽬录下的,创建测试程序。
推荐的创建类和⽅法的提⽰:1、测试类的名称:Test+待测试类名2、测试⽅法的名称:Test+⽅法名称例如:你要测试HelloMaven创建测试类TestHelloMaven@Testpublic void testaDD(){测试HelloMaven的add⽅法是否正确}其中testAdd叫做测试⽅法,定义规则:1、⽅法必须是public的2、⽅法必须没有返回值3、⽅法名称⾃定义,推荐是Test+被测⽅法4、⽅法上⾯加上注解@Test四、举例,Hello项⽬1、新建java源程序,存放在Hello\src\main\java\com\testbk⽬录下,取名HelloMaven.java package com.testbk;import org.junit.Assert;import org.junit.Test;public class TestHelloMaven{@Testpublic void testAdd(){System.out.println("maven junit testAdd()===")HelloMaven hello = new HelloMaven();int res = hello.add(10,20);//验证10+20是不是30,juit提供的⽅法,对⽐结果的//assertEquals(期望值,实际值)Assert.assertEquals(30,res)}}2、新建maven测试类型,存放在Hello\src\main\java\com\testbk⽬录下,取名TestHelloMaven.java package com.testbk;import org.junit.Assert;import org.junit.Test;public class TestHelloMaven{@Testpublic void testAdd(){System.out.println("maven junit testAdd()===")HelloMaven hello = new HelloMaven();int res = hello.add(10,20);//验证10+20是不是30,juit提供的⽅法,对⽐结果的//assertEquals(期望值,实际值)Assert.assertEquals(30,res)}@Testpublic void testAdd2(){System.out.println("#####maven junit testAdd()2###");HelloMaven hello = new HelloMaven();int res = hello.add(10,20);//验证10+20是不是30,juit提供的⽅法,对⽐结果的//assertEquals(期望值,实际值)Assert.assertEquals(50,res);}}3、执⾏mvn clean:清理target⽬录[INFO] Scanning for projects...[INFO][INFO] ------------------------< com.testbk:testjava >-------------------------[INFO] Building maven 0.0.1-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ testjava ---[INFO] Deleting D:\javaProjects\Hello\target[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.196 s[INFO] Finished at: 2021-04-25T22:50:10+08:00[INFO] ------------------------------------------------------------------------4、执⾏mvn compile:编译main/java⽬录下的java为class⽂件,同时把class拷贝到target/classes⽬录下⾯[INFO] Scanning for projects...[INFO][INFO] ------------------------< com.testbk:testjava >-------------------------[INFO] Building maven 0.0.1-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testjava ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] Copying 0 resource[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testjava ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\javaProjects\Hello\target\classes[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.724 s[INFO] Finished at: 2021-04-25T22:54:23+08:00[INFO] ------------------------------------------------------------------------5、执⾏mvn test-compile:编译test/java⽬录下的java为class⽂件,同时class拷贝到target/test-classes⽬录下⾯[INFO] Scanning for projects...[INFO][INFO] ------------------------< com.testbk:testjava >-------------------------[INFO] Building maven 0.0.1-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ testjava ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] Copying 0 resource[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ testjava ---[INFO] Nothing to compile - all classes are up to date[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ testjava ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] Copying 0 resource[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ testjava ---[INFO] Changes detected - recompiling the module![INFO] Compiling 1 source file to D:\javaProjects\Hello\target\test-classes[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.764 s[INFO] Finished at: 2021-04-25T22:55:43+08:00[INFO] ------------------------------------------------------------------------6、执⾏mvn test:查看测试结果,通过1,失败1,并在指定⽬录⽣成测试报告Results :Failed tests: testAdd2(com.testbk.TestHelloMaven): expected:<50> but was:<30>Tests run: 2, Failures: 1, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.050 s[INFO] Finished at: 2021-04-25T22:57:16+08:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project testjava: There are test failures. [ERROR][ERROR] Please refer to D:\javaProjects\Hello\target\surefire-reports for the individual test results.[ERROR] -> [Help 1][ERROR][ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR][ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] /confluence/display/MAVEN/MojoFailureException7、修改测试代码,并再次执⾏mvn testpackage com.testbk;import org.junit.Assert;import org.junit.Test;public class TestHelloMaven{@Testpublic void testAdd(){System.out.println("=====maven junit testAdd()===");HelloMaven hello = new HelloMaven();int res = hello.add(10,20);//验证10+20是不是30,juit提供的⽅法,对⽐结果的//assertEquals(期望值,实际值)Assert.assertEquals(30,res);}@Testpublic void testAdd2(){System.out.println("#####maven junit testAdd()2###");HelloMaven hello = new HelloMaven();int res = hello.add(30,20);//验证10+20是不是30,juit提供的⽅法,对⽐结果的//assertEquals(期望值,实际值)Assert.assertEquals(50,res);}}查看运⾏结果,测试通过T E S T S-------------------------------------------------------Running com.testbk.TestHelloMaven=====maven junit testAdd()===#####maven junit testAdd()2###Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 secResults :Tests run: 2, Failures: 0, Errors: 0, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.282 s[INFO] Finished at: 2021-04-25T22:58:41+08:00 [INFO] ------------------------------------------------------------------------。
使用JUnit和Jacoco进行单元测试

使⽤JUnit和Jacoco进⾏单元测试Jacoco配置<dependency><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.8.0</version></dependency><!--检查代码覆盖率的插件配置--><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>0.8.0</version><executions><execution><id>prepare-agent</id><goals><goal>prepare-agent</goal></goals></execution><execution><id>check</id><goals><goal>check</goal></goals></execution><execution><id>report</id><phase>prepare-package</phase><goals><goal>report</goal></goals></execution></executions><!-- Configuration ⾥⾯写配置信息 --><configuration><!-- rules⾥⾯指定覆盖规则 --><rules><rule implementation="org.jacoco.maven.RuleConfiguration"><element>BUNDLE</element><limits><!-- 指定⽅法覆盖到10% --><limit implementation="org.jacoco.report.check.Limit"><counter>METHOD</counter><value>COVEREDRATIO</value><minimum>0.10</minimum></limit><!-- 指定指令覆盖到10% --><limit implementation="org.jacoco.report.check.Limit"><counter>INSTRUCTION</counter><value>COVEREDRATIO</value><minimum>0.10</minimum></limit><!-- 指定⾏覆盖到10% --><limit implementation="org.jacoco.report.check.Limit"><counter>LINE</counter><value>COVEREDRATIO</value><minimum>0.10</minimum></limit><!-- 指定类覆盖到100%,不能遗失任何类, 为0时指最⼤可丢失数为0, 即覆盖率为100% --><limit implementation="org.jacoco.report.check.Limit"><counter>CLASS</counter><value>MISSEDCOUNT</value><maximum>100</maximum></limit></limits></rule></rules></configuration></plugin>安装Junit插件---------测试⼩例⼦----运⾏。
使用JUnit进行代码测试

使用JUnit进行代码测试在软件开发过程中,代码测试是一个关键的环节,它可以帮助我们发现代码中存在的问题,并及时修复,从而提高软件的质量。
然而,传统的手动测试方式需要耗费大量的时间和人力,而使用JUnit进行代码测试则可以自动化测试过程,提高测试效率。
JUnit是基于Java语言的一个开源测试框架,它主要用于编写和运行单元测试。
在JUnit中,我们可以通过编写测试用例对程序的各个部分进行测试,从而验证代码的正确性和鲁棒性。
下面,我们来看一下如何使用JUnit进行代码测试。
1. 添加JUnit库首先,我们需要在项目中添加JUnit库。
在Eclipse中,可以通过如下步骤添加JUnit库:1) 右键单击项目名称,选择“Build Path” -> “Configure Build Path”。
2) 选择“Libraries”选项卡,点击“Add Library”按钮。
3) 选择“JUnit”库,点击“Next”按钮。
4) 选择JUnit版本,点击“Finish”按钮。
2. 编写测试用例在JUnit中,每个测试用例都是由一个或多个测试方法组成的。
测试方法以@Test注解标记,表示这是一个测试方法。
下面是一个简单的测试用例:import static org.junit.Assert.assertEquals;import org.junit.Test;public class MyTest {@Testpublic void testAdd() {int a = 1;int b = 2;assertEquals(3, a + b);}}在测试用例中,我们可以使用JUnit提供的断言方法进行测试,比如assertEquals()方法用于判断实际值是否等于期望值。
3. 运行测试用例当我们编写好测试用例后,就可以运行测试用例了。
在Eclipse 中,可以通过右键单击测试用例所在类的名称,选择“Run As” -> “JUnit Test”来运行测试用例。
学习使用AndroidStudio进行应用测试

学习使用AndroidStudio进行应用测试一、AndroidStudio应用测试简介在移动应用开发过程中,测试是至关重要的一环。
AndroidStudio是Android开发者常用的集成开发环境(IDE),提供了丰富的测试工具和功能,帮助开发者快速、高效地进行应用测试。
本文将介绍学习使用AndroidStudio进行应用测试的基本知识和技巧。
二、AndroidStudio的测试工具AndroidStudio提供了多种测试工具,主要包括以下几种:1. JUnit测试:AndroidStudio集成了JUnit测试框架,开发者可以使用JUnit进行单元测试,验证代码的正确性。
通过创建测试类和编写测试方法,可以针对应用中的各个模块进行测试。
2. AndroidJUnit测试:AndroidJUnit是Android开发中专门用于测试UI的框架。
它基于JUnit框架扩展了一些针对Android应用的功能,如模拟用户交互、访问UI元素等。
通过使用AndroidJUnit,可以对应用的界面布局、用户交互以及各个UI组件的功能进行测试。
3. Espresso测试:Espresso是一种用于UI自动化测试的框架,可以模拟用户与应用的交互行为,例如点击按钮、输入文本等。
通过编写Espresso测试用例,可以自动化测试应用的各个界面和功能,提高测试效率。
4. UI Automator测试:UI Automator是Android官方提供的一个用于系统级UI自动化测试的工具。
它可以访问应用和设备的底层API,并模拟用户的各种操作,如点击、滑动、截图等。
通过使用UI Automator,可以进行跨应用测试、多个应用交互测试等。
三、使用JUnit进行单元测试JUnit是Java中常用的单元测试框架,也适用于Android应用的单元测试。
下面介绍使用JUnit进行单元测试的基本步骤:1. 在项目的test目录下创建一个新的Java类,命名为XXXTest (XXX为待测试的类名)。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//$JUnit-BEGIN$
suite.addTestSuite(PersonTest2.class);
suite.addTestSuite(PersonTest.class);
<junit printsummary="on"
haltonfailure="false"
failureproperty="tests.failed"
showoutput="true">
<classpath refid="master-classpath"/>
<formatter type="plain"/>
<bottom><![CDATA[<i>All Rights Reserved.</i>]]></bottom>
<!--<tag name="todo"scope="all"description="To do:"/>-->
</javadoc>
</target>
</project>
上面的可以作为一个模板(doc,report,log不要在webRoot下面建立)
JUnit单元测试
将JUnit.jar添加到lib中!
文件:
junit.zip
大小:
114KB
下载:
下载
利用eclipse自带的junit编写测试类
利用ant进行测试运行,以及生成报告文件
例子:
packagecom.wuxiaoxiao.junit;
publicclassPerson{
privateStringname;
this.high=high;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
=name;
}
publicStringgetSex(){
returnsex;
}
publicvoidsetSex(Stringsex){
<mkdir dir="${doc.dir}"/>
<javadoc destdir="${doc.dir}"
author="true"
version="true"
use="true"
windowtitle="TechTiger_Test_API">
<packageset dir="${src.dir}"defaultexcludes="yes">
protected void setUp()throws Exception {
super.setUp();
testPerson=new Person("wxx","boy",175,22);
}
//tearDown()方法则是在每个测试方法之后,释放测试程序方法中引用的变量和实例
protected void tearDown()throws Exception {
</fail>
</target>
<!-- 打包成jar -->
<!--
<target name="pack"depends="test"description="make .jar file">
<mkdir dir="${dist.dir}"/>
<jar destfile="${dist.dir}/hello.jar"basedir="${classes.dir}">
<batchtest todir="${report.dir}">
<fileset dir="${classes.dir}">
<include name="**/AllTests.class"/>
</fileset>
</batchtest>
</junit>
<fail if="tests.failed">
</target>
<!-- 编译 -->
<target name="compile"depends="init"description="compile the source files">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}"destdir="${classes.dir}">
//$JUnit-END$
return suite;
}
}
常用的断言方法:
assertEquals(a,b)
assertNotNull(a)
assertFalse(a):测试a是否为false
assertNull(a)
assertSame(a,b):测试a和b是否=
assertTrue(a)
结合ant进行junit测试:
privateStringsex;
privateinthigh;
privateintage;
publicPerson(Stringname,Stringsex,inthigh,intage){
=name;
this.sex=sex;
this.high=high;
this.age=age;
<exclude name="com/junit/**"/>
<!--<include name="com/wuxiaoxiao/junit/**"/>-->
</packageset>
<doctitle><![CDATA[<h1>Ant_Junit_</h1>]]></doctitle>
}
publicintgetAge(){
returnage;
}
publicbooleansetAge(intage){
if(age>25)
returnfalse;
this.age=age;
returntrue;
}
publicintgetHigh(){
returnhigh;
}
publicvoidsetHigh(inthigh){
<!-- 定义classpath -->
<path id="master-classpath">
<fileset file="${lib.dir}/*.jar"/>
<pathelement path="${classes.dir}"/>
</path>
<!-- 初始化任务 -->
<target name="init">
<classpath refid="master-classpath"/>
</javac>
</target>
<!-- 测试 -->
<target name="test"depends="compile"description="run junit test">
<mkdir dir="${report.dir}"/>
}
publicvLeabharlann id testSetAge(){assertTrue(testPerson.setAge(21));
}
publicvoid testGetHigh(){
assertNotNull(testPerson.getHigh());
}
publicvoid testGetName(){
assertEquals(testPerson.getName(),"wxx");
<exclude name="**/*Test.*"/>
<exclude name="**/Test*.*"/>
</jar>
</target>
-->
<!-- 输出api文档 -->
<target name="doc"depends="test"description="create api doc">
this.sex=sex;
}
}
测试类1(可以单独执行):
package com.wuxiaoxiao.junit;