开发者

How to change the testNG report output name?

My test class is described like this:

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
}

The test report is look like this:

开发者_StackOverflow社区test\tests\text.xml
PASSED: sendRequest(test\tests\text.xml)

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

How can I change the output name in the report ?

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

The problem is, If the dataprovider is providing a long text as sting, then the test report looks horrible.


The test method parameter is simply the .toString() flattening of the argument. You can wrap your File argument in a simple holder like the following:

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

But of course then you have to extract the file from the holder. I've found this technique useful, too, when I expect I might have to add more fields to the @DataProvider output and I don't want to have to change method signatures multiple times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜