Testing Scala Objects

How would you compare the testability of a Scala object compared to static testing in Java? Any traps and traps?

Thank.

+3
source share
2 answers

Just like static in Java, object references are hard to redefine for testing purposes, so you usually want to avoid them other than stateless inaction methods such as Math.min, Math.max. As with Java statics, stateful objects make testing especially difficult.

Scala Java, - . , :

object MyRunnable extends Runnable {
  def run() { }
}

class Client(r: Runnable) {
  // ..
}

new Client(MyRunnable)
new Client(mock[Runnable]) // you can substitute the object with a mock for tests

Java- . Java ( Scala ).

+9

Scala singleton, "object", , Java, , - .

, - , , , Java. , : "var" . " var, period".

+3

All Articles