The usual way to test print statements on the console is to structure your program a bit differently so that you can intercept those statements. You can for example introduce an Output
trait:
trait Output {
def print(s: String) = Console.println(s)
}
class Hi extends Output {
def hello() = print("hello world")
}
And in your tests you can define another trait MockOutput
actually intercepting the calls:
trait MockOutput extends Output {
var messages: Seq[String] = Seq()
override def print(s: String) = messages = messages :+ s
}
val hi = new Hi with MockOutput
hi.hello()
hi.messages should contain("hello world")