TestNG测试在Linux上传递,在Windows上失败

时间:2013-04-10 21:42:27

标签: java testng

出于某种原因,下面的测试在Windows上失败,但在Linux上传递。该测试旨在在被测试的代码中生成异常。该异常基本上是一个文件异常。方法是使文件不可读以生成异常。看起来setReadable(false)对Windows没有影响。

 @Test(dependsOnGroups = "expectedFlow",expectedExceptions = ParserException.class)
 @Parameters("unreadableFile")
 public void mineDataParserExceptionTest(String unreadableFile) throws ParserException{
  AbstractParser parser;
  File f = new File(unreadableFile);
  f.setReadable(false);
  parser = ParserFactory.getParser(ParserFactory.TYPES.SAR);
  parser.mine(fileHelper, xml);
}

1 个答案:

答案 0 :(得分:0)

您应该检查返回值以查看它是否成功;但是,似乎f.setReadable(false, false);可能是一个更好的主意,因为否则它只会改变文件的所有者的读取权限。