51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1748|回复: 0
打印 上一主题 下一主题

junit测试报错,求解?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2012-5-18 14:05:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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...>

哪位仁兄可以帮忙解答一下,万分感谢!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-23 23:36 , Processed in 0.086824 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表