【发布时间】:2015-10-05 23:17:13
【问题描述】:
我有一个显示图像的网络应用程序。我想做一个测试来检查图像是否正确显示。
我的图片在root/src/test/resources/static/images/Head.png。
我的代码是:
这会将图像返回给我。
ResponseEntity<byte[]> entity = new TestRestTemplate().getForEntity("http://localhost/images/Head.png", byte[].class);
这会检查接收到的图像的长度是否正确。
assertEquals("Wrong length\n", entity.getHeaders().getContentLength(), 442526);
现在,我尝试检查内容是否相同,但不起作用。我收到了FileNotFoundException。
final File fichero = new File("/images/Head.png");
final FileInputStream ficheroStream = new FileInputStream(fichero);
final byte[] contenido = new byte[(int)fichero.length()];
ficheroStream.read(contenido);
assertEquals("Wrong content\n", entity.getBody(), contenido);
如何测试接收到的图像和我存储在服务器中的图像是否相同?谢谢
【问题讨论】:
-
FileNotFoundException发生是因为您错误地指定了文件的路径。 -
是的,我知道。但是我应该指定哪个路径才能使其被识别。或者我应该使用其他方式来获取我的文件内容?
标签: java image testing web-applications spring-boot