关于java中测试类的编写:编写DotComBust的测试类

import java.util.*;

public class DotComBust {
private GameHelperr helper = new GameHelperr();
private ArrayList dotComsList = new ArrayList();
private int numOfGuesses = 0;

private void setUpGame() {
    DotCom one = new DotCom();
    one.setName("Pets.com");
    DotCom two = new DotCom();
    two.setName("eToys.com");
    DotCom three = new DotCom();
    three.setName("Go2.com");
    dotComsList.add(one);
    dotComsList.add(two);
    dotComsList.add(three);
    System.out.println("YOUR goal is to sink three dot com!");
    System.out.println("pets.com, eToys.com, Go2.com");
    System.out.println("Try to sink them all in the fewest number of guesses:");
    for (DotCom dotComToset : dotComsList) {
        ArrayList<String> newLocation = helper.placeDotCom(3);
        dotComToset.setLocationCells(newLocation);
    }
}

private void startPlaying() {
    while (!dotComsList.isEmpty()) {
        String userGuess = helper.getUserInput("Enter a guess");
        checkUserGuess(userGuess);

    }
    finishGame();
}

private void checkUserGuess(String userGuess){
numOfGuesses++;
String result = "miss";
for(DotCom dotComToTest : dotComList){
result = dotComToTest.checkYourself(userGuess);
if(result.equals("hit")){
break;
}
if(result.equals("kill")){
dotComList.remove(dotComToTest);
break;
}
}
System.out.println(result);
}
private void finishGame(){
System.out.println("ALL Dot Coms are dead!Your stock is now worthless.");
if(numOfGuesses<=18) {
System.out.println("It only took you" + numOfGuesses + "guesses");
System.out.println("You got out before your options sank");
}
else
{
System.out.println("took you long enoguh"+numOfGuesses+"guesses");
System.out.println("Fish are dancing with your optioons");
}
}
public static void main(String [] args){
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}

}

1个回答

使用junit4编写测试类,推荐下面的博文,写的很不错:
http://blog.csdn.net/andycpp/article/details/1327147

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问