junit执行顺序
Junit 4.11里增加了指定測(cè)試方法執(zhí)行順序的特性
測(cè)試類的執(zhí)行順序可通過對(duì)測(cè)試類添加注解 “@FixMethodOrder(value)” 來指定,其中value 為執(zhí)行順序
三種執(zhí)行順序可供選擇:默認(rèn)(MethodSorters.DEFAULT),按方法名(MethodSorters.NAME_ASCENDING)和JVM(MethodSorters.JVM)
當(dāng)沒有指定任何順序時(shí),按默認(rèn)來執(zhí)行
Sorters
1. MethodSorters.DEFAULT
默認(rèn)順序由方法名hashcode值來決定,如果hash值大小一致,則按名字的字典順序確定
由于hashcode的生成和操作系統(tǒng)相關(guān)(以native修飾),所以對(duì)于不同操作系統(tǒng),可能會(huì)出現(xiàn)不一樣的執(zhí)行順序,在某一操作系統(tǒng)上,多次執(zhí)行的順序不變
2. MethodSorters.NAME_ASCENDING (推薦)
按方法名稱的進(jìn)行排序,由于是按字符的字典順序,所以以這種方式指定執(zhí)行順序會(huì)始終保持一致;
不過這種方式需要對(duì)測(cè)試方法有一定的命名規(guī)則,如 測(cè)試方法均以testNNN開頭(NNN表示測(cè)試方法序列號(hào) 001-999)
3. MethodSorters.JVM
按JVM返回的方法名的順序執(zhí)行,此種方式下測(cè)試方法的執(zhí)行順序是不可預(yù)測(cè)的,即每次運(yùn)行的順序可能都不一樣(JDK7里尤其如此).?
.
package com.kingmed.ms.customer.biz;import java.math.BigDecimal; import java.util.Date;import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.kingmed.ms.customer.CustomerConstant; import com.kingmed.ms.customer.ctrl.KmctCompanyCustomerCtrl; import com.kingmed.ms.customer.entity.CustomerDoctor; import com.kingmed.ms.customer.entity.CustomerDoctorEdit; import com.kingmed.ms.customer.entity.CustomerInfo; import com.kingmed.ms.customer.entity.CustomerInfoEdit; import com.kingmed.ms.customer.vo.KmctPersonalCheckVO; import com.kingmed.ms.customer.vo.KmctPersonalVO; import com.kingmed.ms.util.DateTimeUtils; import com.kingmed.ms.util.StringUtil; import com.kingmed.platform.modules.common.web.vo.datagrid.ResultVO;/** *〈一句話功能簡(jiǎn)述〉* 功能詳細(xì)描述* @author wind* @create 2015年3月16日 下午5:05:54 * @version 1.0.0* @see [相關(guān)類/方法](可選)* @since [KM/MS] (可選)*/ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:spring/applicationContext.xml"}) @ActiveProfiles("development") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class KmctPersonalCustomerBizTest {總結(jié)
- 上一篇: Spark SQL and DataFr
- 下一篇: 纪念互联网第一本众筹电子书Mycat权威