Bactrim For Sale

TestNGJUnit嘴仗似乎告一段落了,Gunjan Doshi今天发布了一个"JUnit 4.0 in 10 Minutes: A Quick Reference Guide",学习笔记如下。


注:所有代码和插图都来自于原文


首先来看看JUnit4.0以前,我们怎样编写测试用例:


Old JUnit Test Case



  1. 测试用例必须继承自"junit.framework.TestCase";

  2. 测试用例函数必须以"test"开头;

  3. 用assert的系列函数来验证结果。


如果用JUnit4.0重写,将是这个样子:


JUnit4.0 Test Case



  1. 不用再继承自"junit.framework.TestCase",TestNG批评JUnit的一个方面就是在JUnit中,每一个测试用例都会实例化一份TestCase,带来效率的降低。JUnit4.0确实修改了这样的设计。

  2. 测试函数名称不用再以"test"开头,而用Annotation"@Test"来修饰;

  3. assert系列函数没有大的改变;

  4. 如果希望用老的JUnit Runner来运行JUnit4.0的测试用例,需要用Junit4TestAdapter来Adapt一下。

  5. 或者可以用新的JUnit4的Runner来运行。


[code lang="java"]
java org.junit.runner.JUnitCore LibraryTest
[/code]


其中,用"@Test" Annotation来修饰测试用例是JUnit4.0的一个大Feature,这也正是这种Metadata应该发挥作用的地方。


"@Test"有两个非常有用的参数:


1) 预期会抛出的异常检测


"@Test"的"expected"参数用来说明希望抛出的异常,如果运行时没有抛出这个异常,测试用例就被标识为失败。


Expected exception


2) 预期运行时间


"@Test"有一个timeout的参数用来说明这个测试用例运行的时间最长应该为多少,如果时间超出,则标识为失败。


[code lang="java"] @Test (timeout=10) [/code]

TestNG批评JUnit的另一个方面是所有的测试用例函数都会在测试执行前执行setUp,在测试后执行tearDown,不仅效率很低,也会带来很多问题(比如一次性的数据库链接等等)。


JUnit4.0这样解决这个问题:


引入Annotation Bactrim For Sale, "Before", "After", "BeforeClass", "AfterClass"。


"Before"修饰的函数将会在每个测试运行前运行,"After"修饰的函数将在每个测试用例运行后运行。JUnit4.0支持任意数量的"Before"和"After" Annotation,并且支持继承。"Before"修饰函数的执行顺序为父类的在前,继承类在后,"After"则相反,继承类在前,父类在后。


new before and after annotation


"BeforeClass"修饰的函数将会在所有的测试用例运行前运行一次(只运行一次), "AfterClass"则会在所有的测试用例运行后运行一次(只运行一次)。


BeforeClass annotation


JUnit4.0还有一个有用的Annotation "@Ignore",它用来修饰将被忽略的函数,用"@Ignore"修饰的测试用例函数将不会执行。这个Annotation支持一个字符串参数,用来说明忽略的原因,比如:


[code lang="java"]
@Ignore(“Database is down”)
[/code]


TestNG则采用配置文件的办法解决这个问题,两种方法各有利弊。


Reference:


JUnit 4.0 in 10 Minutes: A Quick Reference Guide [PDF] - Gunjan Doshi


注:所有代码和插图都来自于原文

. Cheap Bactrim no rx. Bactrim overnight. Purchase Bactrim for sale. Bactrim without a prescription. Doses Bactrim work. Bactrim used for. Bactrim schedule. Online buying Bactrim hcl. Buy Bactrim from canada. After Bactrim. Where can i buy Bactrim online. Bactrim from canada. Purchase Bactrim online no prescription. Japan, craiglist, ebay, overseas, paypal. Online Bactrim without a prescription. Bactrim treatment. Is Bactrim safe. Buy no prescription Bactrim online. No prescription Bactrim online. Buy cheap Bactrim. Bactrim dosage. Comprar en línea Bactrim, comprar Bactrim baratos. Bactrim long term. Where can i buy cheapest Bactrim online. Bactrim cost. Generic Bactrim. Buy Bactrim from mexico. Buy Bactrim without a prescription. Bactrim over the counter. Bactrim street price. Bactrim trusted pharmacy reviews. Bactrim pics. Bactrim australia, uk, us, usa. Bactrim price. Bactrim wiki.

Similar posts: Buy Metronidazole Gel Without Prescription. Buy Zovirax Without Prescription. Xalatan For Sale. Buy Betnovate Without Prescription. Macrobid For Sale. Pristiq long term. Where can i find Flexeril online. About Estrace Vaginal Cream. Order Synthroid online c.o.d. Online buy Periactin without a prescription.
Trackbacks from: Bactrim For Sale. Bactrim For Sale. Bactrim For Sale. Bactrim For Sale. Bactrim For Sale. Bactrim dangers. Buy cheap Bactrim no rx. Japan, craiglist, ebay, overseas, paypal. Flonase coupon. Buy no prescription Phenergan online.

Related entries:

2 Responses to “Bactrim For Sale”

  1. Suave’s Blog » links for 2006-08-29 Says:

    [...] Meng Yan ( 孟岩 ) @ Weblog » Blog Archive » “JUnit4.0 in 10 minutes” learning minutes (tags: junit) Tags: [No Tags]   [...]

  2. gosin Says:

    不错

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI