をスパイを使用した場合、ボイド方法でnullポインタ例外を取得する私は、サービスクラスここJUnitテストで
の「tableInfo」メソッドをテストする必要がありますが、私のJUnitテストスクリプトです:
class JUnitTest extends Specification {
Service service
Table table = GroovyMock(Table)
def spy = Spy(Service){
getTable() >> table
}
def setup() {
service = new Service(
table: table
)
}
def "when table contains information"() {
given:
spy.internalMethod(*_) >> [Bean.BEAN_SUCCESS]
table.getUnits(*_) >> {}
Response response = new Response()
when:
spy.tableInfo(.....)
then:
response.status == 0
response.error == []
}
質問:私は取得しています
以下のようにtable.getUnitsでnullポインタ例外は、 "java.lang.NullPointerExceptionが: nullオブジェクト上)(メソッドのgetUnitsを呼び出すことはできません"
nullオブジェクトを取得する場所を確認し、nullオブジェクトが戻ったときにgetUnits()メソッドを呼び出しません。 – NandhaKumar
私は 'テーブル'クラスにnullオブジェクトを取得しています。私はテストしたいメソッドでtable.getUnits()を呼び出しています。そのメソッドの呼び出しが必要ですright – Muthulakshmi