3

I am trying to write the unit test case for my private method in scala using MockitoSugar but it is throwing Can't find a private method exception. Here is my code.

      object ActivityRepo{

        private def addActivity(activity:Activity):Future[Activity]={
              //doing DB calls
          }
      }

Unit test:

      "Activity Repo Test" must {

        "add Activity" in {
          // doing mock for the DB calls

          val addActivity = PrivateMethod[Future[Activity]]('addActivity)

          val result = ActivityRepo invokePrivate addActivity (activity)
          // doing assertions      
         }
      }

Where is the mistake?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Jet
  • 3,018
  • 4
  • 33
  • 48
  • 1
    I think it can be fixed by adding package access to method: `private[package-name] addActivity` – ulas Feb 06 '16 at 11:34
  • 2
    Maybe you should read this. [Testing Private method using mockito](http://stackoverflow.com/questions/8799439/testing-private-method-using-mockito) – elricfeng May 06 '16 at 01:39
  • Make sure that the type of `activity` is Activity – Gara Walid Apr 22 '22 at 15:27

0 Answers0