ImageVerifierCode 换一换
格式:PPTX , 页数:74 ,大小:1.14MB ,
资源ID:4212835      下载积分:16 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/4212835.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(测试驱动的开发.pptx)为本站上传会员【w****g】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

测试驱动的开发.pptx

1、测试驱动的开发测试驱动的开发l测试驱动的开发l什么是测试驱动的开发l为什么要进行测试驱动的开发l如何进行测试驱动的开发传统测试方法及问题传统测试方法及问题l测试往往不够完整,会导致遗漏的错误;l测试往往由专门的测试人员实施,他们对程序的细节往往不够熟悉l测试人员通常根据文档,而不是代码来觉得究竟要测试哪些内容,而这些文档很容易过期而与代码不一致l大多数的测试是基于手工的,不能够自动完成,因此无法经常执行,即使重复执行往往也不能保证两次测试间的一致性。什么是测试驱动的开发什么是测试驱动的开发l先写单元测试用例,再写代码;l由测试来决定需要什么样的代码;l由程序员编写和维护完整的测试用例集;l仅当

2、代码有了相应的测试代码,该代码才能作为成品代码;一个简单的演示一个简单的演示编写一个能够执行加法和减法的计算器测试驱动的开发的优点测试驱动的开发的优点l能够保证编写单元测试l使得程序员获得满足感,从而始终如一地坚持编写测试l有助于澄清接口和行为的细节l可证明、可再现、可自动验证l改变事物的信心测试驱动的开发的优点测试驱动的开发的优点l让计算机帮你记住l需要实现哪些类、接口和方法l哪些方法还没有实现或者还存在问题什么是什么是JUnitJUnitlJunit是一个测试框架,它的目标是简化单元测试的开发、运行和报告,主要包含以下的功能:l断言(assertions)l测试类和测试集(suites)l

3、测试运行l测试结果报告l对于绝大多数的程序设计语言,都有类似的单元测试框架,他们统称为xUnit。开发开发JunitJunit单元测试的步骤单元测试的步骤l定义一个TestCase的子类.l重载setUp()或者 tearDown()方法(可选).l定义一个或者多个public testXXX()方法,在这个方法中:l操纵测试对象,包括创建对象、组装对象以及调用其中的方法l发起预期结果的断言.l随着测试用例的不断增加,可以创建一个TestSuite类,包含其他的测试用例。l对每一个类中的每一个公共方法(get/set方法除外),至少定义一个测试用例,如果该方法会抛出异常,则需要定义相应的异常测

4、试用例。l可以定义一个main方法以便于该测试用例能够独立于开发环境或者其他工具而运行一个完整的测试用例一个完整的测试用例public class StringTest extends TestCase protected void setUp()/*run before*/protected void tearDown()/*after*/public void testSimpleEqual()String s1=new String(“abcd”);String s2=new String(“abcd”);assertTrue(“Strings not equal”,s1.equals(

5、s2);public static void main(String args)junit.textui.TestRunner.run(suite();Assertions编写测试用例时的几点注意事项编写测试用例时的几点注意事项l使用setup()和 tearDown()来创建、初始化和释放测试用例间公共的测试对象及所需的环境。l确保测试没有副作用,也就是说测试用例运行前后系统的状态保持不变l确保测试用例间没有依赖关系,每一个测试用例都能够独立运行Course Sample public class StudentTest extends TestCase public void testTa

6、keCourse()CourseEvaluationFactory system=CourseEvaluationFactory.getInstance();ICourse course=factory.createCourse(OOT,面向对象技术);IStudent student=factory.createStudent(001,test);int size=course.getStudents().size();student.takeCourse(course);assertEquals(size+1,course.getStudents().size();Course Sampl

7、epublic void testCourseNotAvaliable()CourseEvaluationFactory factory=CourseEvaluationFactory.getInstance();ICourse course=factory.createCourse(OOT,面向对象技术);try int i=0;for(;i course.getAllowStudents();i+)IStudent student=factory.createStudent(i,test);student.takeCourse(course);IStudent student=factor

8、y.createStudent(i+1test);student.takeCourse(course);fail(CourseNotAvailableException expected);catch(CourseNotAvailableException e)TestRunners l基于文本l轻量级,快速l从命令行启动java StringTestjava StringTest.Time:0.05Time:0.05Tests run:7,Failures:0,Errors:0Tests run:7,Failures:0,Errors:0TestRunners-Swingl图形界面,通过启动

9、java junit.swingui.TestRunnerTestRunner:Eclipse IDETestRunner:Eclipse IDETestRunnit:.NETTestRunnit:.NET平台下的平台下的NUnitNUnitlWhen your test contains a failed assertion,Junit counts that as a failed testlWhen your test throws an exception(and does not catch it),Junit counts that as an error.lIf Junits t

10、est runners report the results of a test run in this format:“78 run,2 failures,1 error”From this you can conclude that 75 tests passed,2 failed and 1 was inconclusive.The difference between failures and errorslTest equals methodlTest a method that returns nothinglTest an interfacelTest throwing the

11、right exceptionElementary testslThe mental model of test:The style of test caseThe style of test caseThe style of test caselProblemlYou want to test your implementation of equals()lBackgroundlequals()and hashCode()are important in Java object worldTest your equals methodRecipe:Using EqualsTesterWhy

12、EqualsTester?Why EqualsTester?lProblemlYou want to test a method that has no return valuelBackgroundlA method has no return value has no direct way to determine what such a method does.Test a method that returns nothingCollection related methodlProblemlYou want to test an interface,but there is no w

13、ay to instantiate an interface.You want to test more than just all the current implementations,you want to test all possible implementations.lBackgroundlWhen publishing an interface,the intent is usually to enforce a certain common behavior among all implementations of that interface.So test should

14、be write to capture the requirements of the common behavior of the interface.Testing an interfaceRecipeRecipe(cont.)Example:ListIterator TestExample:ListIterator TestIteratorTestIteratorTestlProblemlYou want to verify that a method throws an excepted exception under the appropriate circumstances.lBa

15、ckgroundlYou should know how JUnit decides whether a test passes or fails.Test Throwing the right exceptionRecipeRecipelTest a constructorlTest a getterlTest a setterOther elementary testslDeciding where to place production code and test codelDealing with duplicate test codelOrganizing special case

16、testslBuilding tests in various development environmentsOrganizing and building Junit testslProblemlYou either do not wish to,or cannot,place test classes in a separate package from the production code under test.lBackgroundlMany Test-Driven practitioners prefer to place their test classes in a sepa

17、rate package from their production code.It is a good practice,but it is not always be applied.Place test classes in the same packagelWhen you write a test class,simply place it in the same package as the production code you plan to test.Your test will have access to all but the private parts of the

18、production classs interface,allowing you to write tests for behavior that would otherwise remain hidden from you.Place test classes in the same packagelProblemlYou want to be able to easily distribute your production code separately from your test code.You would prefer not to confuse yourself or oth

19、ers by mixing up test code with production code.l BackgroundlAlthough we wish that programmers would ship their test code,it is still the norm to distribute production code without the corresponding tests.Create a separate source tree for test codeRecipelProblemlYou have written several tests for th

20、e same production class,and they contain duplicate code.Knowing that duplication is the root of all evil in software,you want to remove it.lBackgroundlThe objects under test is a test fixture.A configuration of objects whose behavior is easy to predict.So,the first part of a test the“create some obj

21、ects”part can be called“create a fixture”.The goal is to create some objects and then initialize them to some known state so that you can predict their responses to invoking methods on them.Factor out a test fixturelIdentify the duplicated test fixture code in your tests.Move that code into a new me

22、thod called setUp.Because each test executes in its own instance of your test case class,there is no need to worry about instance-level fields being set incorrectly from test to test.RecipeRecipeRecipelProblemlYou have multiple test fixtures that share some common objects.There objects are duplicate

23、d in the various TestCase classes that implement your fixture.You would like to reuse these objects,rather than duplicate them.lBackgroundlThis problem arises most frequently when writing customer tests of end-to-end tests that is,tests that target the entire system,rather than a simple class.Factor

24、 out a test fixture hierarchylIf you found test fixtures have common code,you can create a class hierarchy by extracting superclass.This can be done by following the next steps:RecipeRecipelProblemlYou have a common set of methods that you would like to use throughout your tests.It would be nice to

25、refer to these methods as though they were part of the test case class,rather than as class-level methods on some utility class.lBackgroundlIt is very common over time to build up a sizable library of reusable utility methods for Junit tests.Perhaps the most common type of reusable method is the cus

26、tom assertion.The assertion can be extracted into a base TestCaseIntroduce a Base Test CaselIntroduce a base test case that is,a class to act as the superclass for all your test case classes,which we often call BaseTestCase.Even if BaseTestCase has no methods to begin with,starting your project with

27、 a base test case provides a natural place of programmers to put any utility methods that they believe other tests will need to use.RecipelProblemlYou would like to build your tests using the command line,rather than relying on a full-featured IDElBackgroundlYou want a nightly buildlThe target opera

28、tion system does not support your favorite IDEBuild tests from the command linelYou can run Junit in a command-line environment.RecipelProblemlYou need to build you tests in an environment where you cannot use your usual IDE.Youcan build the tests from the command line,but you would like to automate

29、 this task in a portable way.lBackgroundlThere is some serious limitations in using the Java compiler to build your tests:there is no direct support for building all the tests in your test source tree.It is difficult to implement some complicated building process using command-line tools.Build tests

30、 using AntRecipeDesigning for testinglTo test a component,you must be able to control its input(and internal state)and observe its output.If you cannot control the input,you cannot be sure what has caused a given output.If you cannot observe the output of a component under test,you cannot be sure ho

31、w a given input has been processedDesign for testing lSeparation of interface and implementationlAllows substitution of implementation to testslFactory pattern(Or use IoC Container)lProvides for abstraction of creation of implementations from the tests.Design for testing-Mock ObjectslWhen your imple

32、mentation requires a resource which is unavailable for testinglExternal system or database is simulated.lAnother use of Factory,the mock implementation stubs out and returns the anticipated results from a request.lDefinitionlA mock object is an object created to stand in for an object that your code

33、 will be collaborating with.Your code can call methods on the mock object,which will deliver results as set up by your tests.lMock objects are perfectly suited for testing a portion of code logic in isolation from the rest of the code.Mocks replace the objects with which your methods under test coll

34、aborate,thus offering a layer of isolation.Introducing mock objectslMake a bank transfer from one account to anotherMock tasting:a simple exampleClass under testAccountManager as InterfaceMockAccountManagerTest Case for AccountServicelWhats wrong with the following code:Using mock objects as a refac

35、toring techniquelEasy refactoringUsing mock objects as a refactoring techniquelEasy refactoringUsing mock objects as a refactoring techniquelInversion of Control(IoC)lApplying the IoC pattern to a class means removing the creation of all object instances for which this class is not directly responsi

36、ble and passing any needed instances instead.Design patterns in actionlSome people used to say that unit tests should be totally transparant to your code under test,and that you should not change runtime code in order to simplify testing.lThis is wrong.lUnit tests are first-class users of the runtim

37、e code and deserve the same consideration as any other user.Using mock objects as a refactoring techniquelThe biggest advantage of the mock-object approach is that it does not require a running container in order to execute the testslThe drawbacks of using mock objects are:lDo not test interactions with the container or between the componentslDo not test the deployment part of the componentslNeed excellent knowledge of the API being called in order to mock it,which can be difficultPros and cons of mock objectsSpellChecker例例l实现一个拼写检查的组件l该组件能够扩展为对不同类型的输入进行拼写检查,如文本文件,HTML文件等l该组件能够扩展为支持不同类型的语言.

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服