Skip to content

Instantly share code, notes, and snippets.

@tk3
Last active April 15, 2020 14:35
Show Gist options
  • Save tk3/6364a2dcf9940a5cfd7e105b4a952384 to your computer and use it in GitHub Desktop.
Save tk3/6364a2dcf9940a5cfd7e105b4a952384 to your computer and use it in GitHub Desktop.
ScalaTest sampless
name := "SampleTest"
version := "0.1"
scalaVersion := "2.13.1"
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.1.1" % "test"
)
package SampleCase
trait SampleTrait {
def calc(price: Double): Double = {
price * 1.08
}
private[SampleTrait] def calcWithStandardPlan(price: Double): Double = {
(price * 2) * 1.08
}
}
package SampleCase
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.PrivateMethodTester._
class SampleTraitTest extends AnyWordSpec with Matchers {
object SampleTrait extends SampleTrait
"SampleTrait" when {
"calc" must {
"OK" in {
val expected = 108.0
val result = SampleTrait.calc(100)
result shouldEqual expected
}
}
"calcWithStandardPlan" must {
"OK" in {
val expected = 432.0
val calcWithStandardPlan = PrivateMethod[Double](Symbol("calcWithStandardPlan"))
val result = SampleTrait invokePrivate calcWithStandardPlan(200.0)
result shouldEqual expected
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment