Definição
Framework de testes: AnyFunSuite para testes simples, matchers para asserções legíveis.
Exemplos
1. Teste básico
import org.scalatest.funsuite.AnyFunSuite
class TransformSuite extends AnyFunSuite {
test("cleanEmail lowercases and trims") {
assert(cleanEmail(" Anna@Company.COM ") == "anna@company.com")
}
}2. Matchers
import org.scalatest.matchers.should.Matchers
class TransformSpec extends AnyFunSuite with Matchers {
test("dedup keeps one row per key") {
dedup(sampleDf).count() shouldBe 2
}
}3. SparkSession partilhada
trait SparkTest { lazy val spark: SparkSession = SparkSession.builder.master("local[2]").getOrCreate() }
class JobSuite extends AnyFunSuite with SparkTest {
import spark.implicits._
test("filter keeps paid") { Seq(("PAID", 1), ("OPEN", 2)).toDF("status", "n").filter($"status" === "PAID").count() shouldBe 1 }
}