jeudi 1 août 2019

How to stubb a private method call of my tested class

I am actually trying to Test a method, that needs a DB Connection (i cant make it at this moment), so i want to test the method ignoring the DB Connection.

@Test
public void Test(){
         ExampleClass ex = new ExampleClass();

         ex.methodA();
}

My method is calling an inner class, and that class is calling the private method that broke my test. I cant actually call the private method of the Tested class, because is not visible.

public class ExampleClass{

      public methodA(){
                    .......
                    return new innerClass();
      }

      private innerClas(){
            public methodB(){
                             ..........
                              ..........
                              Object a = send(....); //This is my DB Connections that crashes.
            }

      private send(....){
                       .......... 
                         .........
      }
}

I need to ignore the Send method of the Tested class, because there is the DB Connection. If i can stub that send, of ignore it will be enough.

Aucun commentaire:

Enregistrer un commentaire