1

私の問題は、他のクラスをインスタンス化し、そのメソッドを呼び出すメソッドをモックしてテストすることです。プロジェクトのセキュリティについては、詳細には触れません。テストするメソッドは A の launch() メソッドです。テスト仕様では、b.methodOfB が null を返すようにしたかったのです。別のテスト仕様は、c.getinput() メソッドが null を返すためのものです。

public class A{

    public static void launch()
    {
       //instantiation of other classes that will be used
       B b = new B();
       C c = new C();

       //class C has a method that gets user information from the console and returns a string
       //i would like to mock c.getinput() to return null
       while (c.getinput().compareToIgnoreCase("q") != 0) {
           //would also like to mock the b.methodOfB() to return null for testing im having a hard time doing this
           b.methodOfB();//returns something not null
       }

    }

}
4

1 に答える 1