Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Thread.currentThread().getContextClassLoader.getResource()中的文件长度不同_Java_Unit Testing_Scala - Fatal编程技术网

Java Thread.currentThread().getContextClassLoader.getResource()中的文件长度不同

Java Thread.currentThread().getContextClassLoader.getResource()中的文件长度不同,java,unit-testing,scala,Java,Unit Testing,Scala,我试图在单元测试中测量文件长度,但遇到了问题。什么可能会使这个测试失败 val fileName = "filetypes/b.jpg" val root = "C:/Users/Zotov/Work/project/target/test-classes/" val lenAbsolute = new File(root + fileName).length() val lenResource = Thread.currentThread().getContextClassLoader .

我试图在单元测试中测量文件长度,但遇到了问题。什么可能会使这个测试失败

val fileName = "filetypes/b.jpg"
val root = "C:/Users/Zotov/Work/project/target/test-classes/"
val lenAbsolute = new File(root + fileName).length()
val lenResource = Thread.currentThread().getContextClassLoader
  .getResource(fileName).getFile.length()
assertEquals(lenAbsolute, lenResource)
lenAbsolute的值是文件系统报告的值

.... .getResource(fileName).getFile.length()
ClassLoader.getResource方法返回一个URL

getFile方法返回一个字符串

String.length方法返回字符串的长度