Spark unit test -- Mock Azure SQLJDBC connection

Viewed 112

I want to unit test the below piece of code so that i can get good code coverage. I am using FunSuite with Mockito. Can you please let me know how can i mock the database connectiion and do the unit testing.

def getSummaryConfig() : Config = {
    Config(Map(
      "url"            -> configUtil.getProperty("azure.host.name"),
      "databaseName"   -> configUtil.getProperty("azure.database.name"),
      "dbTable"        -> configUtil.getProperty("azure.summary.table"),
      "user"           -> configUtil.getProperty("azure.user.name"),
      "password"       -> configUtil.getProperty("azure.database.password")
    ))
  }

def getSummaryDF(summaryConfig : Config) : DataFrame = {
    val summaryDF = spark.read.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver").sqlDB(summaryConfig)
    summaryDF
  }

val summaryConfig = getSummaryConfig()
val summaryDF  = getSummaryDF(summaryConfig)
0 Answers
Related