J2EE 第二阶段项目之JUnit4进行单元测试(五)
发布日期:2021-08-25 00:12:04 浏览次数:2 分类:技术文章

本文共 1389 字,大约阅读时间需要 4 分钟。

 今天学习了JUnit4进行单元测试。这样就可以不写页面直接进行过功能模块测试。也不是很深入的了解。

JUnit4和自己写的代码可以分割开来。

 首先呢准备两个jar包:

   

 可以对mapper进行测试,当然也可以对service进行测试。

 

  

1 package com.lovo.test; 2  3 import javax.annotation.Resource; 4  5 import org.junit.Test; 6 import org.junit.runner.RunWith; 7 import org.springframework.test.context.ContextConfiguration; 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 import com.lovo.entitys.Teach;10 import com.lovo.service.ITeachService;11 12 // 这里的注释很重要的13 @RunWith(SpringJUnit4ClassRunner.class)14 @ContextConfiguration(locations={   // 这里写路径,如果有多个路径,用逗号隔开15         "classpath:applicationContext.xml"    16 })17 public class TeachServiceTest {18     @Resource19     private ITeachService teachService;20        21      @Test  // 使用该注解的方法为测试方法,自动运行时能够识别并被执行22       public void findTeachById(){23          try {24         Teach t= teachService.findTeachById(1);25         System.out.println(t);26         } catch (Exception e) {27             e.printStackTrace();28         }29            30       }31 }

    出错的情况

 

 

  在文本文档中Ctrl+v 显示出错信息 如

  

  找出错误信息: 就是找不到 applicationContext.xml文件。

 

  正确路径:

   

"classpath:xmls/applicationContext.xml"

 

 

正确结果:

 

 

今天主要是把数据显示出来了。接下来就是增 修改 查询了。

明天就开始         :          2 地区类别统计

                   1 分类别统计

                        1 申报时   (查)

                        2 审批后 (查)         

                   2 分地区统计 

                        1 申报时   (查)

                        2 审批后   (查)

 

转载地址:https://blog.csdn.net/weixin_33836223/article/details/90188746 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android 中文API (68) —— BluetoothClass.Service
下一篇:[LeetCode] Ransom Note 赎金条

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月06日 19时57分21秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

spring boot 与 Ant Design of Vue 实现角色管理布局以及角色的列表(十九) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增角色(二十) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改角色(二十一) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除角色(补二十一) 2019-04-27
spring boot 与 Ant Design of Vue 实现组织管理布局的实现(二十二) 2019-04-27
spring boot 与 Ant Design of Vue 实现左侧组织树(二十三) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增组织(二十四) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改组织(二十五) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除组织(二十六) 2019-04-27
spring boot 与 Ant Design of Vue 实现获取用户列表(二十七) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增用户(二十八) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改用户(二十九) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除用户(三十) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系登录的实现(三十一) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系获取用户信息的实现(三十二) 2019-04-27
Druid连接池实现自定义场景的多数据库的连接 2019-04-27
CentOs7命令行(静默)的方式安装oracle数据库 2021-06-30
基于VMware安装CentOs7的镜像 2021-06-30
PL/SQL数据库管理工具的使用 2021-06-30
史上最简单的spring-boot集成websocket的实现方式 2021-06-30