2011-03-19 75 views
0

我的測試類的描述是這樣的:如何更改testNG報告輸出名稱?

private String TESTFILES = "test/tests"; 

@DataProvider(name = "tests") 
public Iterator<Object[]> readTestFiles() { 
    // read a list of files ... 
} 

@Test(dataProvider = "tests") 
public void sendRequest(File f) throws ParseException { 
    // do something 
} 

試驗報告是這個樣子:

test\tests\text.xml 
PASSED: sendRequest(test\tests\text.xml) 

=============================================== 
    Default test 
    Tests run: 1, Failures: 0, Skips: 0 
=============================================== 

我怎樣才能在報告中改變輸出的名字嗎?

This one:   sendRequest(test\tests\text.xml) 
I'll have instead: sendRequest(text.xml) 

問題是,如果數據提供者提供長文本作爲刺,那麼測試報告看起來很可怕。

回答

1

測試方法參數只是參數的.toString()展平。你可以用你的文件的說法在類似下面的簡單支架:

class FileHolder { 
    private final File file; 
    FileHolder(File f) { 
     this.file = f; 
    } 
    public String toString() { 
     return this.file.getName(); 
    } 
} 

但是,當然,那麼你必須提取從持有人的文件。我發現這種技術也很有用,當我期望可能需要向@DataProvider輸出添加更多字段時,我不想多次更改方法簽名。

+0

thx爲您的快速回答。 – why 2011-03-20 12:35:48