51Testing软件测试论坛

标题: junit测试报错,求解? [打印本页]

作者: helloalex    时间: 2012-5-18 14:05
标题: junit测试报错,求解?
本帖最后由 helloalex 于 2012-5-18 14:07 编辑

测试类为:BoardTest.java
package src.chess;
import junit.framework.*;
import java.util.*;
import src.pieces.*;
import src.util.*;

public class BoardTest extends TestCase  
{
  private Board board;
   
  protected void setUp()  
  {
  board = new Board();
  }
   
  public void testCreate()  
  {
  board.initialize();
  assertEquals(32, board.pieceCount());
  String blankRank = StringUtil.appendNewLine("........");
  assertEquals(16, Piece.whitePieceCount());
  assertEquals(16, Piece.blackPieceCount());
  assertEquals(
  StringUtil.appendNewLine("RNBQKBNR") +
  StringUtil.appendNewLine("PPPPPPP") +
  blankRank + blankRank + blankRank + blankRank +
  StringUtil.appendNewLine("rnbqkbnr") +
  StringUtil.appendNewLine("pppppppp"),
  board.print());
  }
}

生产类为:Board.java
package src.chess;
import java.util.*;
import src.pieces.*;
import src.util.*;

/**
* Represents a chess board
*/
class Board  
{
  private ArrayList<ArrayList<iece>> board = new ArrayList<ArrayList<iece>>();
  private int pieceCount = 0;
   
  public void initialize()  
  {  
Piece.resetCounts();
addBlackBackRank();
addBlackPawnRank();
  addBlankRank();
  addBlankRank();
  addBlankRank();
  addBlankRank();
  addWhitePawnRank();
  addWhiteBackRank();
  }
   
  private void addBlackBackRank()
  {
ArrayList<iece> rank = new ArrayList<iece>();
rank.add(Piece.createBlack(Piece.ROOK));
rank.add(Piece.createBlack(Piece.KNIGHT));
rank.add(Piece.createBlack(Piece.BISHOP));
rank.add(Piece.createBlack(Piece.QUEEN));
rank.add(Piece.createBlack(Piece.KING));
rank.add(Piece.createBlack(Piece.BISHOP));
rank.add(Piece.createBlack(Piece.KNIGHT));
rank.add(Piece.createBlack(Piece.ROOK));
add(rank);
  }
   
  private void addWhiteBackRank()  
  {
ArrayList<iece> rank = new ArrayList<iece>();
rank.add(Piece.createWhite(Piece.ROOK));
rank.add(Piece.createWhite(Piece.KNIGHT));
rank.add(Piece.createWhite(Piece.BISHOP));
rank.add(Piece.createWhite(Piece.QUEEN));
rank.add(Piece.createWhite(Piece.KING));
rank.add(Piece.createWhite(Piece.BISHOP));
rank.add(Piece.createWhite(Piece.KNIGHT));
rank.add(Piece.createWhite(Piece.ROOK));
add(rank);
  }
   
  private void addWhitePawnRank()  
  {
ArrayList<iece> rank = new ArrayList<iece>();
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
rank.add(Piece.createWhite(Piece.PAWN));
add(rank);
  }
   
  private void addBlackPawnRank()  
  {
ArrayList<iece> rank = new ArrayList<;Piece>();
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
rank.add(Piece.createBlack(Piece.PAWN));
add(rank);
  }
   
  private void add(ArrayList<;Piece> rank)  
  {
  board.add(rank);
  pieceCount = pieceCount + rank.size();
  }
   
  private void addBlankRank()  
  {
  Piece blank = Piece.noPiece();
  ArrayList<;Piece> rank = new ArrayList<;Piece>();
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  rank.add(blank);
  board.add(rank);
  }

  int pieceCount()  
  {
  return pieceCount;
  }
   
  public String print()  
  {
  StringBuilder builder = new StringBuilder();
  for (ArrayList<;Piece> rank: board)  
  {
  StringBuilder line = new StringBuilder();
  for (Piece piece: rank)
  line.append(piece.getRepresentation());
  builder.append(StringUtil.appendNewLine(line.toString()));
  }
  return builder.toString();
  }
}
当运行JUNIT测试BoardTest.java的时候会报以下错误
junit.framework.ComparisonFailure: expected:<RNBQKBNR PPPPPPPP...> but was:<;PPPPPPPP RNBQKBNR...>

哪位仁兄可以帮忙解答一下,万分感谢!





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2