I am writing unit test cases using MockitoSugar.
Here is my sample code:
class EmployeeRepo{
def addEmplyees(emp:Employee):Long={
//logic
val res1 = sendReport
val res2 = sendNotification
//logic
}
def sendReport:Boolean={
//logic
}
def sendNotification:Unit={
//logic
}
}
Sample test case:
class TestEmployeeRepo extends WordSpec with MockitoSugar with ScalaFutures{
"TestEmployeeRepo" must {
"add employee" in {
//mock statements
val result = MockEmployeeRepo.addEmplyees(emp)
//assert statements
}
}
}
object MockEmployeeRepo extends EmployeeRepo{
override def sendReport:Boolean = true
override def sendNotification:Unit = //needs unit
}
Here in the above piece of code I am trying to test addEmployee
method with necessary mocking. So while overriding sendNotification
which actually returns Unit
, I am not sure how should I return Unit
.
I tried these two ways:
override def sendNotification:Unit = println("")
override def sendNotification:Unit = Unit
Working fine, but please suggest me the right way to follow and what should be there at //needs unit
. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire