JUnit Java单元测试框架

JUnit是一个Java语言的单元测试框架。它由Kent Beck和Erich Gamma建立,逐渐成为源于Kent Beck的sUnit的xUnit家族中最为成功的一个。 JUnit有它自己的JUnit扩展生态圈。多数Java的开发环境都已经集成了JUnit作为单元测试的工具。

JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试了。

另外junit是在极限编程和重构(refactor)中被极力推荐使用的工具,因为在实现自动单元测试的情况下可以大大的提高开发的效率,但是实际上编写测试代码也是需要耗费很多的时间和精力的,那么使用这个东东好处到底在哪里呢?笔者认为是这样的:

优点:

极限编程
要求在编写代码之前先写测试,这样可以强制你在写代码之前好好的思考代码(方法)的功能和逻辑,否则编写的代码很不 稳定,那么你需要同时维护测试代码和实际代码,这个工作量就会大大增加。因此在极限编程中,基本过程是这样的:构思-> 编写测试代码-> 编写代码-> 测试,而且编写测试和编写代码都是增量式的,写一点测一点,在编写以后的代码中如果发现问题可以较快的追踪到问题的原因,减小回归错误的纠错难度。
 
重构
其好处和极限编程中是类似的,因为重构也是要求改一点测一点,减少回归错误造成的时间消耗。
 
其他情况
我 们在开发的时候使用junit写一些适当的测试也是有必要的,因为一般我们也是需要编写测试的代码的,可能原来不是使用的junit,如果使用 junit,而且针对接口(方法)编写测试代码会减少以后的维护工作,例如以后对方法内部的修改(这个就是相当于重构的工作了)。另外就是因为junit 有断言功能,如果测试结果不通过会告诉我们哪个测试不通过,为什么,而如果是像以前的一般做法是写一些测试代码看其输出结果,然后再由自己来判断结果使用 正确,使用junit的好处就是这个结果是否正确的判断是它来完成的,我们只需要看看它告诉我们结果是否正确就可以了,在一般情况下会大大提高效率。

特性:

JUnit是一个开放源代码的Java测试框架,用于编写和运行可重复的测试。他是用于单元测试框架体系xUnit的一个实例(用于java语言)。它包括以下特性:
1、用于测试期望结果的断言(Assertion)
2、用于共享共同测试数据的测试工具
3、用于方便的组织和运行测试的测试套件
4、图形和文本的测试运行器

637阅读 | 0评论
你的回应
  • ovasimiyau

    2019-04-15 13:44:22 ovasimiyau

    Those gwo.ejdf.osbaike.net.skw.pf cross-regeneration [URL=http://kafelnikov.net/ventolin/]ventolin online[/URL] [URL=http://sammycommunitytransport.org/imitrex/]order imitrex online rx pharmaceutical[/URL] [URL=http://albfoundation.org/careprost/]cheap careprost[/URL] [URL=http://americanartgalleryandgifts.com/prednisone/]prednisone[/URL] [URL=http://metropolitanbaptistchurch.org/vidalista/]vidalista[/URL] [URL=http://cbfsupply.com/cialis-5-mg-best-price-usa/]buying cialis online[/URL] [URL=http://nitromtb.org/revia/]discount revia[/URL] [URL=http://metropolitanbaptistch

  • asugawavud

    2019-04-14 16:02:08 asugawavud

    Remission kiz.qqyt.osbaike.net.obr.bc add appendicectomy, nephrocalcinosis; [URL=http://aakritiartsonline.com/cialis-20-mg/]generic cialis at walmart[/URL] [URL=http://gaiaenergysystems.com/levitra-20mg/]levitra 20mg[/URL] [URL=http://theswordguy.com/levitra/]generic levitra[/URL] [URL=http://stringerstheory.net/cialis/]order cialis online[/URL] [URL=http://gaiaenergysystems.com/buy-prednisone/]prednisone with no prescription[/URL] [URL=http://stringerstheory.net/amoxicillin/]buy amoxicillin[/URL] [URL=http://cbfsupply.com/pharmacy/]canadian pharmacy[/URL] canadi

  • uzocotomveki

    2019-04-08 10:55:50 uzocotomveki

    Here gfr.rkjb.osbaike.net.ksx.bw mine, [URL=http://bayridersgroup.com/prednisone/]prednisone without dr prescription[/URL] [URL=http://kafelnikov.net/prednisone-without-dr-prescription/]prednisone[/URL] [URL=http://gccroboticschallenge.com/doxycycline/]doxycycline[/URL] [URL=http://aawaaart.com/kamagra/]kamagra oral jelly canada[/URL] [URL=http://kafelnikov.net/accutane/]accutane[/URL] [URL=http://gccroboticschallenge.com/buy-kamagra-online/]buy cheap kamagra from india[/URL] pre-renal liposomes wheelchair buy prednisone withou

  • etumivamoq

    2019-03-18 12:54:41 etumivamoq

    Heavy mli.mhmp.osbaike.net.stk.vl blows set [URL=http://websolutionsdone.com/propecia/]propecia[/URL] online propecia http://websolutionsdone.com/propecia/#buy-propecia-online buy propecia online propecia [URL=http://websolutionsdone.com/viagra/]viagra for sale[/URL] viagra uk http://websolutionsdone.com/viagra/#viagra-online viagra [URL=http://openastorenow.com/personal-loan/]personal loans austin tx[/URL] personal loan interest rates in usa http://openastorenow.com/personal-loan/#personal-loan personal loan [URL=http://refrigeratordealers.com/amoxicillin/]500 mg amoxicillin[/URL] amoxil http://refrigeratordealers.com/amoxicillin/#www.amoxicillin500mg.org amoxicillin online [URL=http://refrigeratordealers.com/prednisone/]prednisone[/URL] buy prednisone online http://refrigeratordealers.com/prednisone/#buy-prednisone-online prednisone order [URL=http://anger-management-action.com/payday-loans-irving-tx/]direct online lenders[/URL] payday loans http://anger-management-action.com/payday-loans-irving-tx/#loan-to-pay-off-payday-loans payday loans [URL=http://umichicago.com/short-cash-loans/]cash loans columbus ohio[/URL] cash loans http://umichicago.com/short-cash-loans/#short-cash-loans short cash loans [URL=http://palawan-resorts.com/canadian-pharmacy-online/]canada pharmacy online no script[/URL] pharmacy http:

  • aqimedigiton

    2019-02-25 16:25:39 aqimedigiton

    She zyi.gwmw.osbaike.net.ham.nf stomach; [URL=http://davincipictures.com/retin-a/]buy retin a online[/URL] tretinoin cream 0.1 http://davincipictures.com/retin-a/#where-to-buy-tretinoin-gel retin a cream [URL=http://davincipictures.com/prednisone/]buy prednisone[/URL] buy prednisone without prescription http://davincipictures.com/prednisone/#buy-prednisone prednisone without dr prescription usa [URL=http://davincipictures.com/doxycycline/]doxycycline[/URL]

  • eqotvazexk

    2019-02-19 22:22:25 eqotvazexk

    The wor.jgbv.osbaike.net.myi.os describe pulsatile; dehydrated [URL=http://michiganvacantproperty.org/buy-propecia/]propecia pills[/URL] online propecia http://michiganvacantproperty.org/buy-propecia/#propecia-online-pharmacy propecia pills [URL=http://scoverage.org/celebrex-200-mg/]celebrex[/URL] celebrex 200 mg http://scoverage.org/celebrex-200-mg/#celebrex celebrex generic [URL=http://biblebaptistny.org/nolvadex/]nolvadex in uk[/URL]

  • sedpakewenoba

    2019-02-14 09:42:42 sedpakewenoba

    Later, cle.ycpb.osbaike.net.tfa.hu pre-operatively plus training [URL=http://secretsofthearchmages.net/ventolin/]ventolin[/URL] buy ventolin http://secretsofthearchmages.net/ventolin/ ventolin [URL=http://otrmatters.com/levitra-20mg/]wife levitra[/URL] levitra 20mg http://otrmatters.com/levitra-20mg/ pharmacy prices for levitra [URL=http://kelipaan.com/flagyl/]metronidazole 500 mg antibiotic[/URL] flagyl http://kelipaan.com/flagyl/ buy metronidazole online [URL=http://gocyclingcolombia.com/generic-levitra-vardenafil-20mg/]levitra 20mg[/URL] generic levitra vardenafil 20mg http://gocyclingcolombia.com/generic-levitra-vardenafil-20mg/ levitraonline [URL=http://playinguphockey.com/generic-levitra/]levitra 20 mg[/URL] generic levitra http://playinguphockey.com/generic-levitra/ levitra 20mg vardenafil 20mg [URL=http://webodtechnologies.com/cialis-online/]cialis online[/URL] tadalafil 20mg lowest price http://webodtechnologies.com/cialis-online/ cialis [URL=http://gocyclingcolombia.com/levitra-20-mg/]levitra[/URL] levitra http://gocyclingcolombia.com/levitra-20-mg/ levitra 20 mg [URL=http://webodtechnologies.com/generic-levitra-20mg/]best price levitra 20 mg[/URL] levitra http://webodtechnologies.com/generic-levitra-20mg/ best price levitra 20 mg [URL=http://a1sewcraft.com/walmart-

  • opapijaxigut

    2019-02-13 16:19:45 opapijaxigut

    Background div.dpvo.osbaike.net.hul.ok compensates goes [URL=http://iranascience.com/viagra-generic/]viagra generic[/URL] generic viagra 50mg http://iranascience.com/viagra-generic/ buy viagra online [URL=http://playinguphockey.com/zoloft/]zoloft no prescription[/URL] zoloft no prescription http://playinguphockey.com/zoloft/ zoloft medicine [URL=http://cveto4ki.com/inderal/]inderal[/URL] buy inderal online http://cveto

  • ecebuce

    2019-02-10 18:17:58 ecebuce

    The jmd.skpb.osbaike.net.kob.nm shown aspergillosis [URL=http://gocyclingcolombia.com/cipro/]cipro[/URL] cipro http://gocyclingcolombia.com/cipro/ buy ciprofloxacin 500 mg [URL=http://healinghorsessanctuary.com/levitra/]generic levitra online[/URL] levitra generic 20 mg http://healinghorsessanctuary.com/levitra/ levitra generic lowest prices [URL=http://webodtechnologies.com/retin-a-cream/]retin a cream[/URL] renova cheap http://webodtechnologies.com/retin-a-cream/ retin a online [URL=http://webodtechnologies.com/buy-viagra/]viagra canada[/URL] viagra online canada http://webodtechnologies.com/buy-viagra/ low price viagra 100mg [URL=http://fitnesscabbage.com/generica-cialis/]cialis black[/URL] generica cialis http://fitnesscabbage.com/generica-cialis/ generica cialis [URL=http://dockpartsusa.com/zoloft-online/]buy zoloft[/URL] buy sertraline http://dockpartsusa.com/zoloft-online/ zoloft [URL=http://techiehubs.com/viagra-generic/]buy generic viagra[/URL] viagra generic http://techiehubs.com/viagra-generic/ viagra [URL=http://a1sewcraft.com/furosemide-without-prescription/]diuretic and lasix[/URL] lasix overdose http://a1sewcraft.com/furosemide-without-prescription/ furosemide cat [URL=http://nothingbuthoops.net/viagra/]viagra[/URL]

  • igiwlupu

    2019-02-10 16:22:25 igiwlupu

    Venous, hoa.ystq.osbaike.net.zgm.tt screened poisonous salpingo-oophorectomy [URL=http://desktopindia.com/pharmacy/]pharmacy[/URL] cialis canadian pharmacy http://desktopindia.com/pharmacy/ cialis from canadian pharmacy [URL=http://gocyclingcolombia.com/levitra-20-mg/]levitra[/URL] levitra 20 mg http://gocyclingcolombia.com/levitra-20-mg/ www.levitra [URL=http://ahecanada.com/levitra/]levitra online[/URL] levitra http://ahecanada

1 23
联系我们