I would like to make some unit tests for a function inside my class, simplified example:
Class Datachecks {
df = spark.read.parquet(..)
val logger = Logger(getClass)
def logColumns(df: DatFrame): Unit = {
df.columns.foreach(logger.info(_))
}
Which i then want to test with something like
Class DataChecksSuite extends FunSuite with initSpark {
val initDataChecks = new DataChecks()
val df = spark.read.parquet()
test("Example test") {
assert(initDataChecks.logColumns(df) === "myOutput")
}
}
Now I know this won't run, because my column does not output a String, nor would I like to rewrite/refacter my entire DataChecks Class to make this possible.
Now I was wondering: is it possible to catch the console output of log4j and turn this into a String? Or would it be possible to mock my logger class to output a String? (I have tried with Mockito but without success..)
My (required) dependencies are log4j & FunSuite (if it's really necessary I could still switch, but as the project is rather large I would like to keep all things consistent.
I can provide a more detailed example when needed, as this is only a very simplified spoof example.