多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
在以前开发中,我们测试更多在放在了C层进行,即:我们开发一个M层的类后,需要对应URL,新建一个ACTION,在这个ACTION中去调用我们想测试的类。本节中,我们仍然使用这种方法。 # 配置路由 struts.xml ``` <package name="test" namespace="/test" extends="struts-default"> <action name="teacher" class="test.Teacher"> <result name="success">/jsp/teacher/saveSuccess.jsp</result> </action> </package> ``` # 建立测试类 test.Teacher ``` package test; public class Teacher { public String execute() { return "success"; } } ``` ### 测试: ![](https://box.kancloud.cn/4096382e1a56afd540ebd0b3c66e0585_413x114.png) # 编写测试代码 ``` package test; public class Teacher { public String execute() { // 初例化 entity.Teacher teacher = new entity.Teacher(1,"张三","zhangsan","zhangsan@yunzhiclub.com",false, "123321"); // 打印对象信息 System.out.println(teacher.toString()); return "success"; } } ``` # 测试 ![](./../assets/4.3.test-success.png)