免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2447 | 回复: 0
打印 上一主题 下一主题

测试如何驱动开发 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-28 17:02 |只看该作者 |倒序浏览
需求:反转一个句子
我可能会写出以下的测试——写一个测试,然后写代码让测试通过,然后再写下一个测试。
自己看吧。
  1. public class StringReverseTest {  
  2.   # Test 1
  3.   public void testShouldSplitSentenceIntoWords(){  
  4.     StringReverser sr=new StringReverser();  
  5.     String str = "This is a sentence";  
  6.     Assert.assertEquals(4, sr.split(str).size());
  7.     Assert.assertEquals("sentence", sr.split(str).get(0));  
  8.     Assert.assertEquals("a", sr.split(str).get(1));  
  9.     Assert.assertEquals("is", sr.split(str).get(2));  
  10.     Assert.assertEquals("This", sr.split(str).get(3));  
  11.   }  
  12.   # Test 2
  13.   public void testShouldReverseSentence(){  
  14.     StringReverser sr=new StringReverser();  
  15.     String str = "Tdd is a software devolopment technology";  
  16.     Assert.assertEquals("technology devolopment software a is Tdd",sr.reverse(str));  
  17.   }  
  18.   # Test 3
  19.   public void testShouldAlwaysReverseSentences(){  
  20.     StringReverser sr=new StringReverser();  
  21.     String str = "This is Yet Another sentence";  
  22.     Assert.assertEquals("sentence Another Yet is This",sr.reverse(str));  
  23.   }  
  24. }  
复制代码
原文http://www.javaeye.com/topic/124959
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP