欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    基于测试的JAVA开发案例.ppt

    • 资源ID:5951913       资源大小:452KB        全文页数:53页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    基于测试的JAVA开发案例.ppt

    ,Bowling Game Kata,Object Mentor,Inc.,fitnesse.org,Copyright 2005 by Object Mentor,IncAll copies must retain this page unchanged.,Scoring Bowling.,The game consists of 10 frames as shown above.In each frame the player hastwo opportunities to knock down 10 pins.The score for the frame is the totalnumber of pins knocked down,plus bonuses for strikes and spares.A spare is when the player knocks down all 10 pins in two tries.The bonus forthat frame is the number of pins knocked down by the next roll.So in frame 3above,the score is 10(the total number knocked down)plus a bonus of 5(thenumber of pins knocked down on the next roll.)A strike is when the player knocks down all 10 pins on his first try.The bonusfor that frame is the value of the next two balls rolled.In the tenth frame a player who rolls a spare or strike is allowed to roll the extraballs to complete the frame.However no more than three balls can be rolled intenth frame.,The Requirements.,Write a class named“Game”that has two methodsroll(pins:int)is called each time the player rolls a ball.The argument is the number of pins knocked down.score():int is called only at the very end of the game.It returns the total score for that game.,A quick design session,Clearly we need the Game class.,A quick design session,A game has 10 frames.,A quick design session,A frame has 1 or two rolls.,A quick design session,The tenth frame has two or three rolls.It is different from all the other frames.,A quick design session,The score function mustiterate through all theframes,and calculateall their scores.,A quick design session,The score for a spare or a strike depends on the frames successor,Begin.,Create a project named BowlingGameCreate a unit test named BowlingGameTest,import junit.framework.TestCase;public class BowlingGameTest extends TestCase,Begin.,Create a project named BowlingGameCreate a unit test named BowlingGameTest,import junit.framework.TestCase;public class BowlingGameTest extends TestCase,Execute this program and verify that you get the following error:No tests found in BowlingGameTest,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();,public class Game,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();,public class Game,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i20;i+)g.roll(0);,public class Game,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i20;i+)g.roll(0);,public class Game public void roll(int pins),The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i20;i+)g.roll(0);assertEquals(0,g.score();,public class Game public void roll(int pins),The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i20;i+)g.roll(0);assertEquals(0,g.score();,public class Game public void roll(int pins)public int score()return-1;,expected:but was:,The first test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i20;i+)g.roll(0);assertEquals(0,g.score();,public class Game public void roll(int pins)public int score()return 0;,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(0);assertEquals(0,g.score();public void testAllOnes()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game public void roll(int pins)public int score()return 0;,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(0);assertEquals(0,g.score();public void testAllOnes()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game public void roll(int pins)public int score()return 0;,-Game creation is duplicated-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase public void testGutterGame()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(0);assertEquals(0,g.score();public void testAllOnes()throws Exception Game g=new Game();for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game public void roll(int pins)public int score()return 0;,-Game creation is duplicated-roll loop is duplicated,expected:but was:,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();public void testGutterGame()throws Exception for(int i=0;i 20;i+)g.roll(0);assertEquals(0,g.score();public void testAllOnes()throws Exception for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();public void testGutterGame()throws Exception int n=20;int pins=0;for(int i=0;i n;i+)g.roll(pins);assertEquals(0,g.score();public void testAllOnes()throws Exception for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();public void testGutterGame()throws Exception int n=20;int pins=0;rollMany(n,pins);assertEquals(0,g.score();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testAllOnes()throws Exception for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testAllOnes()throws Exception for(int i=0;i 20;i+)g.roll(1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-roll loop is duplicated,The Second test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();public void testOneSpare()throws Exception g.roll(5);g.roll(5);/spare g.roll(3);rollMany(17,0);assertEquals(16,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-ugly comment in test.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();public void testOneSpare()throws Exception g.roll(5);g.roll(5);/spare g.roll(3);rollMany(17,0);assertEquals(16,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-ugly comment in test.,expected:but was:,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();public void testOneSpare()throws Exception g.roll(5);g.roll(5);/spare g.roll(3);rollMany(17,0);assertEquals(16,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-ugly comment in test.,tempted to use flag to remember previous roll.So design must be wrong.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();public void testOneSpare()throws Exception g.roll(5);g.roll(5);/spare g.roll(3);rollMany(17,0);assertEquals(16,g.score();,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-ugly comment in test.,roll()calculates score,but name does not imply that.,score()does not calculate score,but name implies that it does.,Design is wrong.Responsibilities are misplaced.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();/public void testOneSpare()throws Exception/g.roll(5);/g.roll(5);/spare/g.roll(3);/rollMany(17,0);/assertEquals(16,g.score();/,public class Game private int score=0;public void roll(int pins)score+=pins;public int score()return score;,-ugly comment in test.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();/public void testOneSpare()throws Exception/g.roll(5);/g.roll(5);/spare/g.roll(3);/rollMany(17,0);/assertEquals(16,g.score();/,public class Game private int score=0;private int rolls=new int21;private int currentRoll=0;public void roll(int pins)score+=pins;rollscurrentRoll+=pins;public int score()return score;,-ugly comment in test.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();/public void testOneSpare()throws Exception/g.roll(5);/g.roll(5);/spare/g.roll(3);/rollMany(17,0);/assertEquals(16,g.score();/,public class Game private int score=0;private int rolls=new int21;private int currentRoll=0;public void roll(int pins)score+=pins;rollscurrentRoll+=pins;public int score()int score=0;for(int i=0;i rolls.length;i+)score+=rollsi;return score;,-ugly comment in test.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();/public void testOneSpare()throws Exception/g.roll(5);/g.roll(5);/spare/g.roll(3);/rollMany(17,0);/assertEquals(16,g.score();/,public class Game private int rolls=new int21;private int currentRoll=0;public void roll(int pins)rollscurrentRoll+=pins;public int score()int score=0;for(int i=0;i rolls.length;i+)score+=rollsi;return score;,-ugly comment in test.,The Third test.,import junit.framework.TestCase;public class BowlingGameTest extends TestCase private Game g;protected void setUp()throws Exception g=new Game();private void rollMany(int n,int pins)for(int i=0;i n;i+)g.roll(pins);public void testGutterGame()throws Exception rollMany(20,0);assertEquals(0,g.score();public void testAllOnes()throws Exception rollMany(20,1);assertEquals(20,g.score();public void testOneSpare()throws Exception g.roll(5);g.roll(5);/spare g.roll(3);rollMany(17,0);assertEquals(16,g.score();,public class Game private int rolls=new int21;private int currentRoll=0;public void roll(int pins)rollscurrentRoll+=pins;public int score()int score=0;for(int i=0;i rolls.length;i+)score+=rollsi;return score;,-ugly comment in test.,expected:but was:,The Third test.,import junit.framework.TestCase;public class BowlingGa

    注意事项

    本文(基于测试的JAVA开发案例.ppt)为本站会员(牧羊曲112)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开