我在运行测试时遇到一些麻烦,使用TestNg的@DataProvider为scala编写的测试提供数据。这是我到目前为止所做的。
import org.testng.annotations._
import org.testng.Assert
import org.scalatest.testng.TestNGSuite
import java.lang.Boolean
class PieceTest extends TestNGSuite {
@DataProvider(name= "pieceMovesProvider")
def pieceMovesProvider() = {
Array[Object]( Array[Object](BISHOP, Position(0,0), Position(1,1), Boolean.TRUE))
}
@Test(dataProvider = "pieceMovesProvider")
def testCanTake(piece: Piece, from: Position, to: Position, result: Boolean) = {
Assert.assertEquals(result, piece.canTake(from, to))
//Moves should be commutative
Assert.assertEquals(result, piece.canTake(to, from))
}
@Test def hello() = {
print(1)
}
}
当我运行测试时,hello测试通过,但跳过另一个测试,没有错误或解释。知道这里发生了什么吗?
答案 0 :(得分:1)
数据提供者的返回类型错误。应该是
@DataProvider(name= "pieceMovesProvider")
def pieceMovesProvider() = {
Array( Array[Object](BISHOP, Position(0,0), Position(1,1), Boolean.TRUE))
}