Search code examples
unit-testingscalatestngscalatest

Using TestNG @DataProvider in Scala


I am having some trouble getting a test to run that uses TestNg's @DataProvider to supply data to a test written in scala. Here is what i've got so far.

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)
  }
}

When i run the test the hello test passes but the other test is skipped with no error or explaination. Any idea what is going on here?


Solution

  • The return type of the data provider was wrong. It should have been

    @DataProvider(name= "pieceMovesProvider")
      def pieceMovesProvider() = {
        Array( Array[Object](BISHOP, Position(0,0), Position(1,1), Boolean.TRUE))
      }