나는 조롱하고 싶은 다른 서비스를 사용하는 서비스를 가지고 있습니다. 여기 스프링 부트와 Spock을 이용한 조롱 서비스
@Service
public class CustomerService {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private PatientRepository patientRepository;
@Autowired
private MyHelper myHelper;
public Office createOfficeAccount(Office commonOffice) throws Exception {
// this line calls another service via http, I want to mock it:
Account newAccount = myHelper.createAccount(officeAccount);
return customerRepository.save(customer);
}
내 테스트 클래스입니다 :
class KillBillCustomerServiceTest extends BaseSpecification {
@Autowired
private CustomerService customerService = Mock(CustomerService)
@Autowired
private PatientRepository patientRepository = Mock(PatientRepository)
@Autowired
private MyHelper kbHelper = Mock(MyHelper)
def setup() {
customerService.setPatientRepository(patientRepository)
customerService.setMyHelper(kbHelper)
}
def "create new Account from Common Office"() {
def commonOffice = createOfficeForTests()
CustomerService customerService = new CustomerService (myHelper: kbHelper)
when:
kbHelper.createAccount(commonOffice) >> new Account() // want to mock it, but it is still calling the actual class to try and make the network call
}
내 질문 나는 그것이 실제로 진짜 전화를 시도하지 않도록 내 MyHelper 클래스를 조롱하지만, 대신 그루터기를 돌려 어떻게 목적?
가 Mockito 내가 돈입니다 – Dongqing
을 그것을 http://www.baeldung.com/injecting-mocks-in-spring 확인하는 데 도움이 위에서 무엇을하고있는 것과 다른 것을 생각하지 않아. – sonoerin