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

  關(guān)于 JUnit 測試中某些測試方法的順序信賴性有兩種解決方法:
 
  (但是怎么結(jié)果并沒有達(dá)到我要的效果,我希望如果前面的測試失敗,則后面的所有有信賴于這個測試的測試都失。

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

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

    下面第2種方法是一個不錯的選擇

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

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

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