В groovy / grails я использую SPOC и инфраструктуру junit для модульного тестирования и хочу внедрить MockDatabaseService для модульного теста TestControllerSpec
import org.springframework.beans.factory.annotation.Autowired
import grails.testing.web.controllers.ControllerUnitTest
import spock.lang.Specification
//Controller
class TestController {
@Autowired
BusinessService businessService
def callServiceMethod() {
businessService.callBusinessServiceMethod()
}
}
//Business Service
class BusinessService {
@Autowired
DatabaseService databaseService
def callBusinessServiceMethod() {
databaseService.callDBServiceMethod()
}
}
//Database service
class DatabaseService {
def callDBServiceMethod() {
}
}
//Unit test
class TestControllerSpec extends Specification implements ControllerUnitTest<TestController> {
//Need to pass the MockDatabaseService instead of DatabaseService
def "test "(){
controller.callServiceMethod()
}
}
//Mocked DatabaseService
class MockDatabaseService {
def callDBServiceMethod() {
//Mock method
}
}
Я пытаюсь внедрить Mock for DatabaseService в TestControllerSpec, как мы можем этого достичь?