「SpringでDIされるオブジェクトのMockテスト」の続きです。 その後いろいろ書いていて、これが一番かなという結論に達したので紹介します。 (4) MockitoとReflectionUtilsを使う (3)とやってることは同じです。 @ContextConfiguration(locations = "classpath:context.xml") class ServiceASpec extends Specification { @Autowired private ServiceA serviceA def setup() { RepositoryB repositoryB = Mockito.mock(RepositoryB.class) ReflectionTestUtils.setField(serviceA, "repositoryB", repositoryB) }