Scala : Perform basic test using MOCK and scalatest
Note :
- If you already have scala installed in your system do not add in your scalaVersion := "2.13.0" build file.
- Always add code in the test folder to use mock and scalatest.
build.sbt (I already have scala in my PC hence did not add scalaversion)
name := "sbt_test" version := "0.1"//scalaVersion := "2.13.1"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.0" libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test" libraryDependencies += "org.mockito" % "mockito-all" % "1.8.4" libraryDependencies += "org.scalamock" %% "scalamock" % "4.3.0" % "test" libraryDependencies += "org.testng" % "testng" % "6.10"
Under Project > src > test > scala > test1 > test_class.scala
package test1import org.scalatest.{BeforeAndAfter, FunSpec, FunSuite}import org.scalamock.scalatest.MockFactoryobject test_class extends App with MockFactory{val x=mock[Point]}class Point(xc: Int, yc: Int) {var x: Int = xcvar y: Int = ycdef start(x:Int,y:Int): Unit ={println("start")}def move(dx: Int, dy: Int) {println("move")}def end(dx: Int) {println("end")}}
No comments:
Post a Comment