测试驱动开发TDD培训讲义.ppt_第1页
测试驱动开发TDD培训讲义.ppt_第2页
测试驱动开发TDD培训讲义.ppt_第3页
测试驱动开发TDD培训讲义.ppt_第4页
测试驱动开发TDD培训讲义.ppt_第5页
已阅读5页,还剩35页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、A1,测试驱动的设计和开发基础文章,Charles Huang import JUnit . framework . Test suite;import JUnit . framework . test;public class accountdaomysqltest extends test case public accountdaomysqltest(string name)super(name);a27、JUnit (sample)、2.overridesetUp()和teardown()(如果需要),请在setUp()中选择Database Connection、File I/O或T

2、earDown()上的资源(Database Connection、File I/O和Mock Objects等)public class accountdaomysqltest extends test case privationpublic void setup()throw inxception mysqlfixturins . setup();public void teardown()throw ind exception MySQL fixturins . teardown();a28、Junit(A sample)、3。为测试的Method创建test case public

3、void testaddaccountnormal()accountdaycommsql Dao=new Account dayscomple(),Account=newTry dao.addAccount(帐户);account account _ new=Dao . findbyusername(account . get username();Assertequals (expecting Charles,account . get username()account _ new . get username();Assert equals (expecting Charles,acco

4、unt . get password()account _ new . get password();Assert equals (expecting,account . getemail()account _ new . getemail();Dao . remove account(account . get username();catch(final exception e)e . print stack trace();fail(unexpected exception 3363603360 e . tostring();a29、JUnit (a sample)、public voi

5、d testaddaccountalreadyxist()accountdaycommysql Dao=null;Account=nulltry/add an account Dao . add account(帐户);fail(accountalreadyxistexception expected);catch(final sqlexception e)e . print stack trace();fail(unexpected exception 3363603360 e . tostring();catch(final accountnotfoundexception not fou

6、nd)not found . print stack trace();fail(unexpected exception : not found . tostring();catch(final accountalreadyxistexception ex)/passtry pdao . remove account(account . get username();catch(final sqlexception SQL)SQL . printstacktrace();故障排除(Unexpected exception,fail);A30,JUnit,运行此设备测试。Junit位于swing

7、(JUnit . swing ui . test runner)c : sandboxforumjava-class path ./classes;/lib/JUnit . jar;/lib/MySQL _ JDBC . jar;/lib/tidy . jar;/lib/struts . jar JUnit . swing ui . Test runner org . redsoft . forum . Dao . MySQL . accountdaomysqltest,a31,JUnit (a sample)public class all tests public static void

8、main(string args)JUnit . text ui . test runner . run(suite();public static test suite()test suite=new test suite();/添加到子程序包中的alltest suite suite . add test(org . redsoft . forum . Dao . MySQL . all tests . suite();/添加到此package level的unit test case suite . add test suite(mysqldatasource test . class)

9、中。Return suite/EOC、a34、JFC Unit、Junit的扩展,用于测试基于摆动的应用程序。最简单的:示例测试之一是Login Screen、a35、JFC Unit,代码片断:测试首选参数private log ins creen log ins creen=null;Private TestHelper helper=nullpublic loginscreentest(string name)super(name);protectedvoidsetup()throw inxception super . setup();helper=new JFCTestHelper(

10、);log inscreen=new log inscreen(log inscreen test : get name();log in screen . set visible(true);protected void tear down()throws exception log ins creen=null;helper . clean up(this);super . tear down();代码片断:测试图形界面JDialog dialogj button exit button=(j button)helper . findnamedcomponent(exit button,l

11、ogins creen,0);assert not null(could not find the exit button,exit button);jbutton enter button=(j button)helper . findnamedcomponent(enter button,loginscreen,0);assert not null(could not find the enter button,enter button);JT field username field=(JT field)helper . findnamedcomponent(login name tex

12、tfield,loginscreen,0);assert not null(could not find the username field,username field);Asser tequals(username field is empty,username field . get text();jtfield password field=(jtfield)helper . findnamedcomponent(password textfield,loginscreen,0);assert not null(could not find the password field,pa

13、ssword field);assert equals(password field is empty,password field . get text();a36、对Nightly Test使用Ant、Ant的Tasks自动运行Nightly Test生成XML示例结果报告,并生成可以使用JunitReport导航的结果文件。a37,测试案例复盖范围,使用NOUnit测试案例复盖范围(,a38,单位测试:100%始终,如果单位测试出现错误(Junit的进度指示器中显示红色),XP团队的第一个任务是Junit进度如果不更正错误的测试示例,则会产生雪球效应,因此,基于未知质量代码进行开发只会增加未知质量的代码。软件质量的基石开始崩塌。A39、Software Q

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论