我有一个服务,它有一个存储库作为构造函数的参数。
@Autowired
NodeServiceListInstallService( final BykiListRepository aBykiListRepository )
该BykiListRepository是没有实现默认春库
interface BykiListRepository extends JpaRepository<BykiList, Long> {
//some magic methods
}
我的配置类标有@EnableJpaRepositories,所以,我没有直接bean的声明。服务声明:
@SpringBootApplication
@EnableConfigurationProperties( ApplicationProperties )
@EnableJpaRepositories
@EnableTransactionManagement
@ImportResource( 'classpath:META-INF/spring/application-context.xml' )
class Application extends SpringBootServletInitializer {
@Bean
NodeServiceListInstallService nodeServiceListInstallService( final BykiListRepository bykiListRepository ) {
new NodeServiceListInstallService( bykiListRepository )
}
}
我正在尝试在存储库方法的调用中编写一个测试save将引发异常PersistenceException。我尝试存根/监视一个存储库并将其声明为@TestConfigurationwith 中的 bean @Primary,甚至实现该接口。但我还没有得到结果。
@TestConfiguration
class TestConfig {
@Bean
BykiListRepository bykiListRepository() {
//return Spock's Spy/Stub or new BykiRepositoryBadImpl()
}
测试:
@ContextConfiguration( classes = TestConfig )
class GlobalErrorHandlerIntegrationTest extends BaseFlowIntegrationTest {
//test()
}
我Groovy-2.4.12用Spock-1.1. Spring Boot 1.5.4. 保留的变体是使用方面,但不完全是我想要的。将非常感谢帮助。
侃侃尔雅
智慧大石
相关分类