2012-03-27 17 views
0

我有幾個單元測試需要測試數據的字符串非常大。我不想在測試中聲明HTML字符串,因爲這會掩蓋實際的測試。相反,我想從每個測試的外部資源加載這些字符串。寫入參數化測試失敗,出現以下情況:檢索測試用例參數時發生錯誤:導致參數化字段的值無效

儘管我沒有對不同的數據集進行相同的測試,但參數化測試看起來是一個可行的解決方案;然而,我很難得到下面的例子工作。

注意:此代碼基於TestNG example

package flexUnitTests 
{ 
    import helpers.HTMLDataHelper; 

    import org.flexunit.runners.Parameterized; 
    import org.hamcrest.assertThat; 
    import org.hamcrest.text.containsString; 

    [RunWith("org.flexunit.runners.Parameterized")] 
    public class SimpleTestCase 
    { 
     private var parameterized:Parameterized; 

     public static var dataLoader:HTMLDataHelper = new HTMLDataHelper("data/layer.html"); 

     [DataPoint(loader="dataLoader")] 
     public static var htmlContent:String; 

     [Test(dataprovider="htmlContent", description="Tests something.")] 
     public function mustPassThisSimpleTest(htmlContentParam:String):void 
     { 
      assertThat(htmlContentParam, containsString("head")); 
     } 
    } 
} 

當我運行這個測試我收到以下錯誤信息:

Error: There was an error retrieving the parameters for the testcase: cause invalid value for parameterized field htmlContent: null

任何想法,以什麼可能是解決這個問題可能是什麼?

回答

0

我發現的一個解決方案是使用Theories轉輪在班級中運行測試,如下所示。

​​

但副作用是測試失敗時,測試類中的所有測試都將顯示隱蔽的錯誤消息。例如,

Error: mustWorkWithRegularTests

,而不是有用得多

Error: Expected: a string containing "head" 
but: was "this is some text" 

雖然這並「解決」我是有這個問題,恕我直言,在信息透明度的權衡是不值得能夠加載數據來自外部來源。