当前位置: 首页 > news >正文

建设科技网络网站的意义和目的福田区做网站公司

建设科技网络网站的意义和目的,福田区做网站公司,wordpress防cc,wordpress 静态html测试案例6种编写方法测试。 我最近一直在考虑测试。 作为我对各种项目所做的代码审查的一部分#xff0c;我已经看到了数千行未经测试的代码。 这不仅是测试覆盖率统计数据指出这一点的情况#xff0c;更是该项目中根本没有任何测试的情况 。 我一直听到这种悲惨状况的两个原… 测试案例6种编写方法 测试。 我最近一直在考虑测试。 作为我对各种项目所做的代码审查的一部分我已经看到了数千行未经测试的代码。 这不仅是测试覆盖率统计数据指出这一点的情况更是该项目中根本没有任何测试的情况 。 我一直听到这种悲惨状况的两个原因是什么 “我们没有时间”紧随其后的是“完成代码后就去做”。 我在这里介绍的不是万能药。 它涵盖了单元测试尤其是接口的单元测试。 接口是好东西。 接口定义合同。 接口无论接口有多少种实现都可以轻松轻松地进行测试。 让我们看看如何使用此类结构作为示例。 CustomerService是我们的界面。 为了使示例保持简单它有两种方法下面将进行介绍。 请注意javadoc-这是描述合同的地方。 public interface CustomerService {/*** Retrieve the customer from somewhere.* param userName the userName of the customer* return a non-null Customer instance compliant with the userName* throws CustomerNotFoundException if a customer with the given user name can not be found*/Customer get(String userName) throws CustomerNotFoundException;/*** Persist the customer.* param customer the customer to persist* return the customer as it now exists in its persisted form* throws DuplicateCustomerException if a customer with the user name already exists*/Customer create(Customer customer) throws DuplicateCustomerException; } 从图中可以看到我们有两个此类的实现RemoteCustomerService和CachingCustomerService。 这些的实现未显示因为它们无关紧要。 我怎么说呢 很简单–我们正在测试合同。 我们为接口中的每个方法以及合约的每个排列编写测试。 例如对于get我们需要测试存在具有给定用户名的客户时发生的情况以及不存在时发生的情况。 public abstract class CustomerServiceTest {Testpublic void testCreate(){CustomerService customerService getCustomerService();Customer customer customerService.create(new Customer(userNameA));Assert.assertNotNull(customer);Assert.assertEquals(userNameA,customer.getUserName());}Test(expected DuplicateCustomerException.class)public void testCreate_duplicate(){CustomerService customerService getCustomerService();Customer customer new Customer(userNameA);customerService.create(customer);customerService.create(customer);}Testpublic void testGet(){CustomerService customerService getCustomerService();customerService.create(new Customer(userNameA));Customer customer customerService.get(userNameA);Assert.assertNotNull(customer);Assert.assertEquals(userNameA,result.getUserName());}Test(expected CustomerNotFoundException.class)public void testGet_noUser(){CustomerService customerService getCustomerService();customerService.get(userNameA);}public abstract CustomerService getCustomerService(); } 现在我们对合同进行了测试并且我们从未提及任何实现。 这意味着两件事 我们不需要为每个实现重复测试。 这是一件非常好的事情。 没有一个实现正在测试中。 我们可以通过为每个实现添加一个测试类来纠正此问题。 由于每个测试类几乎都是相同的因此我将仅演示RemoteCustomerService的测试。 public class RemoteCustomerServiceTest extends CustomerServiceTest {public CustomerService getCustomerService(){return new RemoteCustomerService();} } 就是这样 现在我们有了一种非常简单的方法来测试任何接口的多个实现方法是预先进行艰苦的工作并将测试新实现的工作减少到一个简单的方法中。 参考 Objective博客上的JCG合作伙伴 Steve Chaloner 编写测试的一种好方法 。 翻译自: https://www.javacodegeeks.com/2013/06/a-good-lazy-way-to-write-tests.html测试案例6种编写方法
http://www.zqtcl.cn/news/173641/

相关文章:

  • wap 网站 源码网站建立
  • 辽阳专业建设网站公司山东省工程建设招标信息网站
  • 下载专门做初中数学题的网站佛山网站制作在线
  • 永康物流网站蒙牛企业网站建设规划书
  • 网站开发发和后台开发有什么区别马鞍山网站建设价格
  • 广州建设银行预约公积金网站怎么下载ppt免费模板
  • 网站策划的基本过程网站设置在哪
  • 内蒙古住房和城乡建设网站网站建设需要购买什么
  • 网站做调查问卷给钱的兼职南通营销网站制作
  • 开个微网站需要什么自己制作网页的步骤
  • 有专业做线切割配件的网站吗中国婚恋网站排名
  • 做ppt网站大全中国工程建设信息网站
  • 汉滨区住房和城乡建设局网站淘宝客购物网站的怎么做
  • 一个网站用多个域名分页网站
  • 门户网站举例phpstuy wordpress
  • 做网站许昌美业管理软件系统排名
  • 温州市建设工程质量安全管理总站贵阳最新消息今天
  • 成都服装网站建设工作是否能给我们带来快乐
  • 电商网站建设综述长沙高端网站建设
  • 网站建设有哪些环节怎么申请网址
  • 做网站要什么软件经典网站首页
  • 个人网站备案转公司备案长沙网站seo报价
  • 上海网站开发建设电话电影vip网站建设步骤
  • 17.zwd一起做网站池尾站邢台快用网络科技有限公司
  • 做写字楼租赁用什么网站好如何申请网站com域名
  • 如何查询网站服务商安徽省建设厅证件查询安全员c证
  • asp网站怎么安装程序员wordpress插件
  • 池州网站建设哪家好郑州seo网站管理
  • 我要建个人网站国外免备案虚拟主机
  • 自建站 外贸做旅游网约车的网站