我如何在jala的Scala中执行IOException.class?

时间:2018-11-02 15:04:07

标签: scala junit

我在scala中编写了这个单元测试:

@Test(expected = Class[IOException].getClass)
def tryToConvertWhenFileAlreadyExistsTest(): Unit = {
  CsvToParquetConverter.convertAndSaveAsANewFile(exceptionalArgumentMap)
}

预期值应为Class[_ <: Throwable]

但无法编译,我得到的错误是:

Error:(115, 20) class java.lang.Class is not a value
  @Test(expected = Class[IOException].getClass)

Error:(115, 39) annotation argument needs to be a constant; found: 
Class[IOException].<getClass: error>
  @Test(expected = Class[IOException].getClass)

我该如何解决?

1 个答案:

答案 0 :(得分:0)

我原来应该做classOf[IOException]