javaWeb服务详解【客户端调用】(含源代码,测试通过,注释) ——测试

本文展示了一个使用Spring框架进行部门(Dept)和员工(Emp)服务的单元测试案例。测试包括从XML配置文件初始化应用上下文,获取部门及员工服务实例,并验证部门及其下属员工信息的正确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Dept测试

@Test
	public void test() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		IDeptService deptService = (IDeptService) ctx.getBean("wsClient");
		List<Dept> depts = deptService.getDepts();
		for (Dept dept : depts) {
			System.out.println("部门名称:"+dept.getDname()+",部门地址:"+dept.getLoc());
			System.out.println("员工表:"+dept.getEmps());
		}
	}

Emp测试

IEmpService empService;
	@Before
	public void init(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		 empService=(IEmpService)ctx.getBean("wsClientEmp");
	}
	@Test
	public void testGetEmps() {
		List<Emp> getEmps= empService.getEmps();
		for (Emp emp : getEmps) {
			System.out.println(emp.getEname());
			System.out.print("\t"+emp.getJob());
			System.out.print("\t"+emp.getComm());
			System.out.print("\t"+emp.getDept().getDname());
		}
	}
	
	@Test
	public void testGetEmpById() {
		Emp emp = empService.getEmpById(7369);
	
			System.out.println(emp.getEname()+"*********"+emp.getEmpno()+"*********"+emp.getDept().getDname());
		
	}


转载于:https://www.cnblogs.com/a1111/p/7459654.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值