서비스를 조롱하고 서비스 인스턴스를 클래스 인스턴스에 할당하는 것의 차이점은 무엇입니까? 예를 들어Grails 유닛 테스트 모의 서비스 대 서비스 인스턴스 할당
:
class MyService {
def CallServiceMethod(){
my business logic
}
}
class MyController {
def myService
def callServiceMethod(){
myService.callServiceMethod()
}
}
@TestFor(MyController)
class MyControllerTests {
@Before
void setup() {
controller?.myService = new MyService()
vs
controller?.myService = mockFor(MyService)
}
void testCallServiceMethod(){
controller.callServiceMethod()
}
}
중 하나가 제발 도와 드릴까요?