junit 单元测试,测试上传相片
来源:互联网 发布:如何在手机上淘宝购物 编辑:程序博客网 时间:2024/05/16 01:46
/**
* 上传文件单元测试
*
*/
public class uploadImgTest extends AbstractTest {
/**
*通过图片路径把图片转换成byte[]
*/
public static byte[] imageToByteArray(String imgPath) {
BufferedInputStream in;
try {
in = new BufferedInputStream(new FileInputStream(imgPath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int size = 0;
byte[] temp = new byte[1024];
while((size = in.read(temp))!=-1) {
out.write(temp, 0, size);
}
in.close();
return out.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* 测试模板文件上传
*/
@Test
public void testUploadSample()throws Exception{
//byte[]info=
final String fileName = "get.jpg";
final byte[] content = this.imageToByteArray("D:/File/get.jpg");
System.out.println(content);
MockMultipartFile file =
new MockMultipartFile("file", fileName, "image/jpeg", content);//把byte[]图片转换成服务器可以都去的MockMultipartFile类型
MockMultipartHttpServletRequest request1 = new MockMultipartHttpServletRequest();//模拟请求
MockHttpServletResponse response1 = new MockHttpServletResponse();//模拟响应
String url = "/files/image/uploadphoto.do";//请求路径
request1.setRequestURI(url);
request1.setMethod("POST");
//request1.addParameter("goodsid", "148");
request1.addFile(file);
handle(request1, response1);
String json = response1.getContentAsString();
ResponseResult sample = (ResponseResult) JSONObject.toBean(JSONObject.fromObject(json),
ResponseResult.class);
Assert.assertNotNull(sample);
}
}
* 上传文件单元测试
*
*/
public class uploadImgTest extends AbstractTest {
/**
*通过图片路径把图片转换成byte[]
*/
public static byte[] imageToByteArray(String imgPath) {
BufferedInputStream in;
try {
in = new BufferedInputStream(new FileInputStream(imgPath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int size = 0;
byte[] temp = new byte[1024];
while((size = in.read(temp))!=-1) {
out.write(temp, 0, size);
}
in.close();
return out.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* 测试模板文件上传
*/
@Test
public void testUploadSample()throws Exception{
//byte[]info=
final String fileName = "get.jpg";
final byte[] content = this.imageToByteArray("D:/File/get.jpg");
System.out.println(content);
MockMultipartFile file =
new MockMultipartFile("file", fileName, "image/jpeg", content);//把byte[]图片转换成服务器可以都去的MockMultipartFile类型
MockMultipartHttpServletRequest request1 = new MockMultipartHttpServletRequest();//模拟请求
MockHttpServletResponse response1 = new MockHttpServletResponse();//模拟响应
String url = "/files/image/uploadphoto.do";//请求路径
request1.setRequestURI(url);
request1.setMethod("POST");
//request1.addParameter("goodsid", "148");
request1.addFile(file);
handle(request1, response1);
String json = response1.getContentAsString();
ResponseResult sample = (ResponseResult) JSONObject.toBean(JSONObject.fromObject(json),
ResponseResult.class);
Assert.assertNotNull(sample);
}
}
0 0
- junit 单元测试,测试上传相片
- Android测试:单元测试Junit
- 软件测试(java JUnit单元测试)
- 软件测试(JUnit实施单元测试)
- 软件测试之JUnit单元测试
- Junit单元测试写多线程测试
- Android 单元测试01--JUnit测试
- 单元测试之Junit测试框架
- junit单元测试不支持多线程测试
- 相片上传
- [软件测试]JUnit和单元测试入门简介
- Struts2单元测试 使用Junit测试Action
- 如何写好单元测试(Junit测试)?
- java 单元测试(回归测试)(junit)
- android中关于测试和JUnit单元测试
- Android JUnit单元测试周期,异常,测试套件
- Android 中Junit 测试框架(单元测试)
- java单元测试junit测试线程问题
- PODOFO编译之3——可用篇
- MySql数据库的列类型(字段类型)
- 工作点滴2 - Cisco IP Event Dampening - 思科IP事件抑制机制
- TextView添加链接
- 由Clang LLVM 1.0 Error error: -fobjc-arc is not supported with fragile abi说起
- junit 单元测试,测试上传相片
- mysql联合索引与Where子句优化浅析
- js小技巧:复制内容时自动加上一段文本
- GObject对象系统
- Mysql优化方法
- ssl is not supported
- oracle drop数据表的恢复
- 以图搜图的一些知识
- Ubuntu下搭建Android SDK开发环境(图文)