1.单元测试
框架:junit框架
测试方法:白盒测试,主要对代码的路径覆盖、错误处理等进行测试。
步骤:
1、添加依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
2、创建测试类
1>在被测试类中使用快捷键 Ctrl+Shift+T,选择要测试的方法。
2>编写测试类
package dao;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.*;
public class ImageDaoTest {
@Before
public void before(){
System.out.println("----------before--------------");
}
@After
public void after(){
System.out.println("----------after--------------");
}
@Ignore
@Test
public void insert() {
//准备测试数据
ImageDao imageDao = new ImageDao();
Image image = new Image();
image.setImageName("test.png");
image.setUploadTime("20200629");
image.setPath("./image/fbab242a577efdf0c530a27a92e0c255");
image.setMd5("fbab242a577efdf0c530a27a92e0c255");
image.setContentType("image/png");
image.setSize(45197);
//测试,在数据库中可查看是否插入成功
imageDao.insert(image);
}
@Test
public void selectAll() {
ImageDao imageDao = new ImageDao();
List<Image> lists = imageDao.selectAll();
System.out.println(lists.size());
System.out.println();
for (Image image:lists) {
System.out.println("imageId = " + image.getImageId()+" "+"imageName = "+image.getImageName());
}
}
@Test
public void selectOne() {
ImageDao imageDao = new ImageDao();
try {
Image image = imageDao.selectOne(2);
System.out.println(image.getImageName());
System.out.println(image.getImageId());
System.out.println(image.getSize());
System.out.println(image.getMd5());
}catch (Exception e){
System.out.println("查询失败,imageId 不存在!!!");
}
}
@Test
public void delete() {
ImageDao imageDao = new ImageDao();
List<Image> lists1 = imageDao.selectAll();
System.out.println("删除前图片容量" + lists1.size());
imageDao.delete(54);
List<Image> lists2 = imageDao.selectAll();
System.out.println("删除后图片容量" + lists2.size());
if(lists1.size()>lists2.size()) {
System.out.println("删除成功");
}else {
System.out.println("删除失败,imageId 不存在!!!");
}
}
@Test
public void selectByMd5() {
ImageDao imageDao = new ImageDao();
try {
Image image = imageDao.selectByMd5("fbab242a577efdf0c530a27a92e0c255");
System.out.println(image.getImageId());
System.out.println(image.getImageName());
System.out.println(image.getPath());
} catch (Exception e) {
System.out.println("查询失败,Md5 不存在!!!");
}
}
}
2.系统功能测试
测试用例
测试方法:黑盒测试。
自动化测试_selenium
自动化测试:进行兼容性测试,浏览器不同(版本、类型),查看项目是否正常显示。
性能测试_loadrunner
3.项目bug
1.删除图片后刷新页面图片依旧存在
原因:删除图片未删除干净(上传时本地还有一份图片数据,删除时未删除)
2.上传已删除过的图片显示写失败,再次刷新页面才会显图片
原因:删除图片未删除干净(上传时本地还有一份图片数据,删除时未删除)
3.上传非图片的文件上传成功
建议:上传时进行判断
4.上传空文件上传成功
建议:上传时进行判断
5.全部图片在同一个页面,图片过多时,对服务器压力过大
原因:未分页
6.图片名称过长时未折行展示,影响美观
建议:折行展示