您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
JUnit測(cè)試中某些測(cè)試方法的順序信賴性
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/19 15:14:34 ] 推薦標(biāo)簽:

  關(guān)于 JUnit 測(cè)試中某些測(cè)試方法的順序信賴性有兩種解決方法:
 
 。ǖ窃趺唇Y(jié)果并沒(méi)有達(dá)到我要的效果,我希望如果前面的測(cè)試失敗,則后面的所有有信賴于這個(gè)測(cè)試的測(cè)試都失。

  1、為每個(gè)測(cè)試類添中一個(gè) suite() 方法

 public static Test suite() {
  TestSuite suite = new TestSuite("edu.dhu.zkl.tools.FileSwithWithMemoryTest");
 
  // 下面添加測(cè)試方法的順序即使 JUnit 運(yùn)行測(cè)試的順序
  suite.addTest( new FileSwithWithMemoryTest( "testLoadFileIntoMemory" );
  suite.addTest( new FileSwithWithMemoryTest( "testStoreMemoryIntoFile" );
 
  return suite;
 }
 
    但是這種方法要將 FileSwithWithMemoryTest 中所有的測(cè)試方法都添加進(jìn)來(lái),當(dāng) FileSwithWithMemoryTest 中
測(cè)試方法多,而要指定有序的測(cè)試方法少時(shí),則讓人感到厭煩。

    下面第2種方法是一個(gè)不錯(cuò)的選擇

  2、為每個(gè)測(cè)試類添中一個(gè) suite() 方法

 public static Test suite() {
  String[] orderDependentTests = new String[] {
   "testLoadFileIntoMemory",
   "testStoreMemoryIntoFile"
  };
 
  return new OrderdTestSuite(
   FileSwithWithMemoryTest.class, orderDependentTests );
 }
 
    這種方法要用到 GSBase jar包(Mike Bowler)

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd