对线上论坛进行单元测试的测试报告
源码地址:https://gitee.com/coisini-thirty-three/forum
一、用户部分(UserServiceImplTest)
1.创建普通用户
测试名称 |
createNormalUser() |
测试源码 |
@Test void createNormalUser() { // 构造用户 User user = new User(); user.setUsername("TestUser"); user.setNickname("单元测试用户"); user.setPassword("123456"); user.setSalt("123456"); //调用Service userService.createNormalUser(user); System.out.println("注册成功"); // System.out.println("================="); // user.setUsername("bitboy"); // userService.createNormalUser(user); // System.out.println("注册成功"); } |
测试结果 |
 |
预期结果 |
注册成功 |
实际结果 |
注册成功 |
2.用户登录
测试名称 |
login() |
测试源码 |
@Test void login() throws JsonProcessingException { // 正常用户 User user = userService.login("bitgirl", "123456"); System.out.println(objectMapper.writeValueAsString(user)); } |
测试结果 |
 |
预期结果 |
返回用户信息 |
实际结果 |
返回用户信息 |
3.根据用户名查询用户信息
测试名称 |
selectByName() |
测试源码 |
@Test void selectByName() throws JsonProcessingException { User user = userService.selectByName("bitboy"); System.out.println(objectMapper.writeValueAsString(user)); System.out.println("=========================="); user = userService.selectByName("bitboy111"); System.out.println(objectMapper.writeValueAsString(user)); System.out.println("=========================="); // user = userService.selectByName(null); // System.out.println(objectMapper.writeValueAsString(user)); } |
测试结果 |
 |
预期结果 |
返回用户信息 |
实际结果 |
返回用户信息· |
4.根据Id查询用户信息
测试名称 |
selectById() |
测试源码 |
@Test void selectById() throws JsonProcessingException { //bitboy User user = userService.selectById(1l); System.out.println(objectMapper.writeValueAsString(user)); //bitgril user = userService.selectById(2l); System.out.println(objectMapper.writeValueAsString(user));
//null user = userService.selectById(20l); System.out.println(objectMapper.writeValueAsString(user)); } |
测试结果 |
 |
预期结果 |
返回用户信息 |
实际结果 |
返回用户信息 |
5.用户发帖数 +1
测试名称 |
addOneArticleCountById() |
测试源码 |
@Test //加了事务的注解之后,测试的结果不在持久化到数据库,测试通过之后,写入的 数据会被回滚,从而不污染数据库 @Transactional // 更新的测试,建议在方法级别上加入事务注解, void addOneArticleCountById() { userService.addOneArticleCountById(1l); System.out.println("更新成功");
userService.addOneArticleCountById(2l); System.out.println("更新成功");
// userService.addOneArticleCountById(100l); // System.out.println("更新成功");
} |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
6.用户发帖数 -1
测试名称 |
subOneArticleCountById() |
测试源码 |
@Test void subOneArticleCountById() { userService.subOneArticleCountById(1l); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
7.修改个人信息
测试名称 |
modifyInfo() |
测试源码 |
@Test @Transactional void modifyInfo() { User user = new User(); user.setId(2l); user.setNickname("bitgirl"); user.setGender((byte) 0); user.setPhoneNum("123456789"); user.setEmail("123456@qq.com"); user.setRemark("我是一个美丽的小女孩"); //调用service userService.modifyInfo(user); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
8.修改用户密码
测试名称 |
modifyPassword() |
测试源码 |
@Test void modifyPassword() { userService.modifyPassword(1l,"123456","123"); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更像成功 |
二、帖子部分(ArticleServiceImplTest)
1.查询所有的帖子集合
测试名称 |
selectAll() |
测试源码 |
@Test void selectAll() throws JsonProcessingException { List<Article> result = articleService.selectAll(); System.out.println(objectMapper.writeValueAsString(result)); } |
测试结果 |
 |
预期结果 |
返回帖子列表 |
实际结果 |
返回帖子列表 |
2.根据板块id查询帖子列表
测试名称 |
selectByBoardId() |
测试源码 |
@Test void selectByBoardId() throws JsonProcessingException { //Java板块 List<Article> articles = articleService.selectByBoardId(1l); System.out.println(objectMapper.writeValueAsString(articles)); //c++ 板块 articles = articleService.selectByBoardId(2l); System.out.println(objectMapper.writeValueAsString(articles)); //不存在的 articles = articleService.selectByBoardId(100l); System.out.println(objectMapper.writeValueAsString(articles)); } |
测试结果 |
 |
预期结果 |
返回帖子列表 |
实际结果 |
返回帖子列表 |
3.发布新贴
测试名称 |
create() |
测试源码 |
@Test @Transactional void create() { Article article = new Article(); article.setBoardId(9l); article.setUserId(1l); article.setTitle("单元测试标题1"); article.setContent("单元测试内容1"); //调用Service articleService.create(article); System.out.println("写入成功"); } |
测试结果 |
 |
预期结果 |
写入成功 |
实际结果 |
写入成功 |
4.根据帖子id查询帖子列表
测试名称 |
selectById() |
测试源码 |
@Test void selectById() throws JsonProcessingException { Article article = articleService.selectById(1l); System.out.println(objectMapper.writeValueAsString(article));
article = articleService.selectById(19l); System.out.println(objectMapper.writeValueAsString(article));
article = articleService.selectById(900l); System.out.println(objectMapper.writeValueAsString(article)); } |
测试结果 |
 |
预期结果 |
返回帖子信息 |
实际结果 |
返回帖子信息 |
5.根据用户id查询帖子列表
测试名称 |
selectByUserId() |
测试源码 |
@Test void selectByUserId() throws JsonProcessingException { List<Article> articles = articleService.selectByUserId(1l); System.out.println(objectMapper.writeValueAsString(articles));
articles = articleService.selectByUserId(2l); System.out.println(objectMapper.writeValueAsString(articles));
articles = articleService.selectByUserId(100l); System.out.println(objectMapper.writeValueAsString(articles)); } |
测试结果 |
 |
预期结果 |
返回帖子列表 |
实际结果 |
返回帖子列表 |
6.更新帖子的访问数量
测试名称 |
updateVisitCountById() |
测试源码 |
@Test void updateVisitCountById() { articleService.updateVisitCountById(1l); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
7.根据帖子id更新帖子标题和内容
测试名称 |
modify() |
测试源码 |
@Test void modify() { articleService.modify(25l,"测试提示效果111","测试贴是效果222"); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
8.根据Id删除帖子
测试名称 |
void deleteById() |
测试源码 |
@Test @Transactional void deleteById() { articleService.deleteById(16l); System.out.println("删除成功"); } |
测试结果 |
 |
预期结果 |
删除成功 |
实际结果 |
删除成功 |
9.根据article更新对象
测试名称 |
updateById() |
测试源码 |
@Test @Transactional void updateById() { Article article = new Article(); article.setId(1l); article.setUpdateTime(new Date()); articleService.updateById(article); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
10.点赞帖子
测试名称 |
thumbsUpById() |
测试源码 |
@Test @Transactional void thumbsUpById() { articleService.thumbsUpById(1L); System.out.println("点赞成功"); } |
测试结果 |
 |
预期结果 |
点赞成功 |
实际结果 |
点赞成功 |
三、帖子回复部分(ArticleReplyServiceImplTest)
1.根据帖子Id查询回复列表
测试名称 |
selectByArticleId() |
测试源码 |
@Test void selectByArticleId() throws JsonProcessingException { List<ArticleReply> articleReplies = articleReplyService.selectByArticleId(1l); // System.out.println(objectMapper.writeValueAsString(articleReplies));
// articleReplies = articleReplyService.selectByArticleId(100l); // System.out.println(objectMapper.writeValueAsString(articleReplies));
Assertions.assertNotNull(articleReplies); System.out.println("根据帖子Id查询回复列表"); } |
测试结果 |
 |
预期结果 |
返回帖子列表 |
实际结果 |
返回帖子列表 |
2.新增一个回复记录
测试名称 |
create() |
测试源码 |
@Test @Transactional void create() { ArticleReply articleReply = new ArticleReply(); articleReply.setArticleId(3l); articleReply.setPostUserId(2l); articleReply.setContent("单元测试"); //调用service articleReplyService.create(articleReply); System.out.println("回复成功"); } |
测试结果 |
 |
预期结果 |
回复成功 |
实际结果 |
回复成功 |
四、板块部分(BoardServiceImplTest)
1.查询首页的板块列表
测试名称 |
selectByNum() |
测试源码 |
@Test void selectByNum() throws JsonProcessingException { List<Board> boards = boardService.selectByNum(9); System.out.println(objectMapper.writeValueAsString(boards)); } |
测试结果 |
 |
预期结果 |
返回板块列表 |
实际结果 |
返回板块列表 |
2.根据id查询板块信息
测试名称 |
selectById() |
测试源码 |
@Test void selectById() throws JsonProcessingException { //Java Board board = boardService.selectById(1l); System.out.println(objectMapper.writeValueAsString(board)); //c++ board = boardService.selectById(2l); System.out.println(objectMapper.writeValueAsString(board)); //不存在 board = boardService.selectById(100l); System.out.println(objectMapper.writeValueAsString(board)); } |
测试结果 |
 |
预期结果 |
返回板块信息 |
实际结果 |
返回板块信息 |
3.版块中的帖子数量 +1
测试名称 |
addOneArticleCountById() |
测试源码 |
@Test void addOneArticleCountById() { boardService.addOneArticleCountById(1l); System.out.println("更新成功");
boardService.addOneArticleCountById(2l); System.out.println("更新成功");
} |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
4.版块中的帖子数量 -1
测试名称 |
subOneArticleCountById() |
测试源码 |
@Test @Transactional void subOneArticleCountById() { boardService.subOneArticleCountById(7l); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新成功 |
实际结果 |
更新成功 |
五、站内信部分(MessageServiceImplTest)
1.发送站内信息
测试名称 |
create() |
测试源码 |
@Test @Transactional void create() { Message message = new Message(); message.setPostUserId(2l); message.setReceiveUserId(1l); message.setContent("单元测试"); messageService.create(message); System.out.println("发送成功"); } |
测试结果 |
 |
预期结果 |
发送成功 |
实际结果 |
发送成功 |
2.根据Id查询站内信
测试名称 |
selectById() |
测试源码 |
@Test void selectById() throws JsonProcessingException { Message message = messageService.selectById(1l); System.out.println(objectMapper.writeValueAsString(message)); } |
测试结果 |
 |
预期结果 |
返回站内信 |
实际结果 |
返回站内信 |
3.根据用户Id查询该用户未读数量
测试名称 |
selectUnreadCount() |
测试源码 |
@Test void selectUnreadCount() { Integer count = messageService.selectUnreadCount(1l); System.out.println("未读数量为: " + count); count = messageService.selectUnreadCount(2l); System.out.println("未读数量为: " + count); count = messageService.selectUnreadCount(20l); System.out.println("未读数量为: " + count); } |
测试结果 |
 |
预期结果 |
返回未读数量 |
实际结果 |
返回未读数量 |
4.根据接收者用户Id查询所有站内信
测试名称 |
selectByReceiveUserId() |
测试源码 |
@Test void selectByReceiveUserId() throws JsonProcessingException { List<Message> messages = messageService.selectByReceiveUserId(1l); System.out.println(objectMapper.writeValueAsString(messages));
messages = messageService.selectByReceiveUserId(2l); System.out.println(objectMapper.writeValueAsString(messages));
messages = messageService.selectByReceiveUserId(20l); System.out.println(objectMapper.writeValueAsString(messages)); } |
测试结果 |
 |
预期结果 |
返回回复私信 |
实际结果 |
返回回复私信 |
5.更新指定站内信的状态
测试名称 |
updateStateById() |
测试源码 |
@Test @Transactional void updateStateById() { messageService.updateStateById(1l, (byte) 1); System.out.println("更新成功"); } |
测试结果 |
 |
预期结果 |
更新时间 |
实际结果 |
更新时间 |
6.回复站内信
测试名称 |
reply()文章来源:https://uudwc.com/A/0k1dk |
测试源码 |
@Test void reply() { // 构建对象 Message message = new Message(); message.setPostUserId(1l); message.setReceiveUserId(2l); message.setContent("单元测试回复"); // 调用service messageService.reply(2l, message); System.out.println("回复成功"); }文章来源地址https://uudwc.com/A/0k1dk |
测试结果 |
 |
预期结果 |
回复成功 |
实际结果 |
回复成功 |
原文地址:https://blog.csdn.net/qq_59561046/article/details/132940528
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!