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

做网站字体规范建站宝盒合作

做网站字体规范,建站宝盒合作,网页设计案例100例,小程序api文档昨天我在办公室里#xff0c;和我的一位同事谈论测试#xff0c;他对编写单元测试有些不服气。 他使用的原因之一是有些测试似乎毫无意义#xff0c;这使我想到了什么是单元测试#xff0c;什么也不需要打扰。 考虑下面一个简单的不可变的Name Bean#xff0c;其中包含一… 昨天我在办公室里和我的一位同事谈论测试他对编写单元测试有些不服气。 他使用的原因之一是有些测试似乎毫无意义这使我想到了什么是单元测试什么也不需要打扰。 考虑下面一个简单的不可变的Name Bean其中包含一个构造函数和一堆getter。 在这个示例中我将让代码说明一切因为我希望任何测试都是毫无意义的。 public class Name {private final String firstName;private final String middleName;private final String surname;public Name(String christianName, String middleName, String surname) {this.firstName christianName;this.middleName middleName;this.surname surname;}public String getFirstName() {return firstName;}public String getMiddleName() {return middleName;}public String getSurname() {return surname;} } ……只是为了强调这一点这是毫无意义的测试代码 public class NameTest {private Name instance;Beforepublic void setUp() {instance new Name(John, Stephen, Smith);}Testpublic void testGetFirstName() {String result instance.getFirstName();assertEquals(John, result);}Testpublic void testGetMiddleName() {String result instance.getMiddleName();assertEquals(Stephen, result);}Testpublic void testGetSurname() {String result instance.getSurname();assertEquals(Smith, result);} } 测试此类毫无意义的原因是该代码不包含任何逻辑。 但是当您向Name类添加如下内容时 public String getFullName() {if (isValidString(firstName) isValidString(middleName) isValidString(surname)) {return firstName middleName surname;} else {throw new RuntimeException(Invalid Name Values);}}private boolean isValidString(String str) {return isNotNull(str) str.length() 0;}private boolean isNotNull(Object obj) {return obj ! null;} …然后整个情况发生了变化。 以if语句的形式添加一些逻辑会生成大量测试 Testpublic void testGetFullName_with_valid_input() {instance new Name(John, Stephen, Smith);final String expected John Stephen Smith;String result instance.getFullName();assertEquals(expected, result);}Test(expected RuntimeException.class)public void testGetFullName_with_null_firstName() {instance new Name(null, Stephen, Smith);instance.getFullName();}Test(expected RuntimeException.class)public void testGetFullName_with_null_middleName() {instance new Name(John, null, Smith);instance.getFullName();}Test(expected RuntimeException.class)public void testGetFullName_with_null_surname() {instance new Name(John, Stephen, null);instance.getFullName();}Test(expected RuntimeException.class)public void testGetFullName_with_no_firstName() {instance new Name(, Stephen, Smith);instance.getFullName();}Test(expected RuntimeException.class)public void testGetFullName_with_no_middleName() {instance new Name(John, , Smith);instance.getFullName();}Test(expected RuntimeException.class)public void testGetFullName_with_no_surname() {instance new Name(John, Stephen, );instance.getFullName();} 因此鉴于我刚刚说过您不需要测试不包含任何逻辑语句的对象并且在逻辑 语句列表中我将包含if并与所有运算符一起切换 -*- 以及可能发生变化和对象状态的一整套事物。 在此前提下我建议在我前两篇博客中一直在讨论的Address项目中为地址数据访问对象DAO编写单元测试毫无意义。 DAO由AddressDao接口定义并由JdbcAddress类实现 public class JdbcAddress extends JdbcDaoSupport implements AddressDao {/*** This is an instance of the query object thatll sort out the results of* the SQL and produce whatever values objects are required*/private MyQueryClass query;/** This is the SQL with which to run this DAO */private static final String sql select * from addresses where id ?;/*** A class that does the mapping of row data into a value object.*/class MyQueryClass extends MappingSqlQueryaddress {public MyQueryClass(DataSource dataSource, String sql) {super(dataSource, sql);this.declareParameter(new SqlParameter(Types.INTEGER));}/*** This the implementation of the MappingSqlQuery abstract method. This* method creates and returns a instance of our value object associated* with the table / select statement.* * param rs* This is the current ResultSet* param rowNum* The rowNum* throws SQLException* This is taken care of by the Spring stuff...*/Overrideprotected Address mapRow(ResultSet rs, int rowNum) throws SQLException {return new Address(rs.getInt(id), rs.getString(street),rs.getString(town), rs.getString(post_code),rs.getString(country));}}/*** Override the JdbcDaoSupport method of this name, calling the super class* so that things get set-up correctly and then create the inner query* class.*/Overrideprotected void initDao() throws Exception {super.initDao();query new MyQueryClass(getDataSource(), sql);}/*** Return an address object based upon its id*/Overridepublic Address findAddress(int id) {return query.findObject(id);}} 在上面的代码中接口中的唯一方法是 Overridepublic Address findAddress(int id) {return query.findObject(id);} ……这实际上是一种简单的吸气方法。 在我看来这是可以的因为DAO中确实不应包含属于AddressService的任何业务逻辑该业务逻辑应具有大量的单元测试。 您可能要决定是否要为MyQueryClass编写单元测试。 对我来说这是一个临界情况所以我期待任何评论…… 我猜想有人会不同意这种方法说您应该测试JdbcAddress对象这是真的我亲自为其编写了一个集成测试以确保我使用的数据库可以正常运行并且可以理解我的数据库SQL并且两个实体DAO和数据库可以互相通信但是我不会打扰对其进行单元测试。 总而言之单元测试必须是有意义的并且对“有意义”的良好定义是被测对象必须包含一些独立的逻辑。 参考 您应该对什么进行单元测试 – Captain Debug博客上的 JCG合作伙伴 Roger Hughes的 测试技术3 相关文章 测试技巧–不编写测试 端到端测试的滥用–测试技术2 常规单元测试和存根–测​​试技术4 使用模拟的单元测试–测试技术5 为旧版代码创建存根–测试技术6 有关为旧版代码创建存根的更多信息–测试技术7 为什么要编写单元测试–测试技巧8 一些定义–测试技术9 使用FindBugs产生更少的错误代码 在云中开发和测试 翻译自: https://www.javacodegeeks.com/2011/11/what-should-you-unit-test-testing.html
http://www.yutouwan.com/news/26603/

相关文章:

  • 科技类网站简介怎么做网站空间是先备案后买
  • 河南建设银行招聘网站网站建设后期
  • 企业被网站骗做会员移动端网站和app区别
  • 高要网站建设公司品牌宣传方案
  • phpstudy2016快速搭建网站手机开发人员选项在哪
  • 网站301做下国家企业信息官网查询
  • 金融行业网站建设方案公司想做个自己的网站怎么做的
  • 雄安网站建设费用中国建设工程电子信息网
  • 黑龙江省网站前置审批网站成都建站费用
  • 免费开源网站微信网站页面设计
  • 织梦网站首页内容wordpress链接样式表
  • 网站套餐方案百度账户登录
  • 北京建站模板制作每一个网站都是响应式吗
  • wordpress第三方登录组件公司网站优化方案
  • 购物网站开发公司wordpress付费阅读文章功能
  • 常德网站建设的策划方案自己做文学网站赚钱吗
  • 网站建设咨询网站建设亮点
  • 鼎维重庆网站建设专家长沙市政务服务中心官网
  • 做ppt图片用的网站有哪些问题wordpress自定义结构404
  • 开公司做网站有什么网站可以免费建站免费建网站
  • 做药品网站有哪些内容网站添加备案信息
  • 专业外包网站建设公司排名沧州网站建设制作设计优化
  • 网站甚而模板wordpress图片无法显示
  • 连云港做网站哪里好网站如果建设
  • dedecms网站地图前台路径不修改搜索引擎推广费用
  • 狗狗和人做网站丹东搜索引擎优化
  • 公司网站建设哪家公司好电子商务网站建设的核心多选
  • 国外网站制作wordpress 提交评论
  • 东莞做网站建设wordpress 安装 此网页包含重定向循环
  • 常州新北区网站建设现在推广平台哪家最好