-
1 votesanswersviews
Spring Boot测试 - 没有合格Bean异常
在尝试使用Spring Boot框架进行一些测试时,我遇到了一个问题,即找到测试单元所依赖的Bean . Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authServerApplication': Unsatisfied dep... -
1 votesanswersviews
使用@TestPropertySource属性中的属性会导致NullPointerException
我有以下测试: @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest @TestPropertySource(value = "classpath:testApplication.properties") public class ESJavaAPITests { @Resource private ... -
1 votesanswersviews
无法加载ApplicationContext(Spring Boot)
我正试图在Spring网站上的示例后测试我的应用程序 . 这些是我的依赖: dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile("org.springframework.boot:spring-boot-starter-security")... -
0 votesanswersviews
如何测试自己拥有自动连接依赖项的Spring服务bean?
我想测试一些他们自己包含其他自动服务的服务 . 但是测试本身并不需要这些“外部”服务 . 如何创建测试设置,例如以下示例? package de.myapp.service; @Service public class MyServiceDelegator { @Autowired private List<ServiceInterface> services; ... -
4 votesanswersviews
Spring @Autowired构造函数导致@Value在测试类中实例化时返回null
我在服务中使用自动装配的构造函数,当在测试类中实例化时,会导致@Value注释返回null . 自动装配依赖项直接解决了问题,但项目遵循使用基于构造函数的自动装配的惯例 . 我的理解是,在测试类中实例化服务并不是从Spring IoC容器创建它,导致@Value返回null . 有没有办法使用基于构造函数的自动装配从IoC容器创建服务,而无需直接访问应用程序上下文? 示例服务: @Componen... -
1 votesanswersviews
MockMvc测试POST请求
我的REST控制器中有以下发布路径: @RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json") public ResponseEntity saveMovie(@RequestBody Movie movie){ movieServ... -
1 votesanswersviews
使用Spring MVC和Mockito从MockMvc Test中没有JSON内容(来自null)
有一个代码库,它使用SpringMVC 4.0.3.RELEASE进行Restful Web Services . Codebase包含一个功能齐全的Restful Web服务,我可以使用postman和curl验证工作 . 但是,当尝试使用MockMvc为特定的Restful Web Service编写单元测试时,我试图从单元测试中获取JSON内容时被阻止 . 我想知道它是配置问题还是我没有正确... -
4 votesanswersviews
Spring Boot - Test - Validator:Validator的目标无效
当我尝试运行测试时,我收到以下错误: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Invalid target for Validator [userCreateFormVali... -
7 votesanswersviews
为什么来自appliction.properties的属性在Spring启动应用程序的Junit测试中不可用?
我有一个 Spring 季启动应用程序 . 我正在写Junit测试 . 我试图从application.properties(在src / main / resources / application.properties中定义)和在AppConfig中配置的Status bean(src / main / java / hello / AppConfig.java)中注入值 . 我看到bean是... -
7 votesanswersviews
如何为通过Spring注入的mapstruct抽象映射器编写Junit测试
我正在使用MapStruct,mapstruct-jdk8版本1.1.0.Final并定义我通过Spring注入的抽象类 . 我正在研究如何通过Junit Test测试它们?我基本上是一个主映射器,它将使用2个子映射器 @Mapper(componentModel = "spring", uses = {SubMapper1.class, SubMapper2.class}) ... -
22 votesanswersviews
使用spring boot禁用单元测试的安全性
我正在尝试用安全性创建一个简单的spring boot web项目 . 我可以正常启动应用程序,安全性正常 . 但是,我有一些我想要测试的组件没有安全性(或者根本没有测试 - 我根本无法进行测试) . 我得到一个异常,表明它找不到ObjectPostProcessor,因此无法启动容器 . 引起:org.springframework.beans.factory.NoSuchBeanDefinit... -
17 votesanswersviews
在Integration测试中覆盖bean
对于我的Spring-Boot应用程序,我通过@Configuration文件提供了RestTemplate,因此我可以添加合理的默认值(ex Timeouts) . 对于我的集成测试,我想模拟RestTemplate,因为我不想连接到外部服务 - 我知道期望的响应 . 我尝试在集成测试包中提供不同的实现,希望后者将覆盖实际的实现,但是反过来检查日志:真正的实现覆盖了测试 . How can I ... -
14 votesanswersviews
Spring重写主bean与非主bean
我试图在使用@Primary在测试配置中声明的测试期间覆盖Spring bean . 一个声明位于src / main / java路径中,另一个声明位于src / test / java路径中 . 但是,Spring故意用非主bean替换主bean,这是我不想用于测试的bean . 如果我只是注释掉 生产环境 (src / main / java)配置bean,它会根据需要在测试配置中使用主测试... -
0 votesanswersviews
我应该如何在JUnit5 Spring MVC集成测试中添加环境属性?
我正在使用JUnit 5中的 MockMvcBuilders.webAppContextSetup() 编写集成测试 . 我'm extending with Sam Brannen' s SpringExtension 和 MockitoExtension . (真的,我正在使用组合的SpringJUnitJupiterWebConfig) 我在运行测试(编辑)时得到此输出: java.l... -
1 votesanswersviews
测试 spring mvc休息控制器
我正在尝试使用MockMvcBuilders.standaloneSetup方法为spring mvc rest控制器创建一个非常基本的单元测试 . 我一直收到404错误 . 下面我列出我的测试应用程序上下文,我的测试类,我的控制器和完整的堆栈跟踪 . 任何指导表示赞赏 . @Configuration public class TestContext { @Bean public... -
9 votesanswersviews
用thymeleaf测试spring-boot web-app
我正在尝试编写测试以确保我的控制器加载我的视图 . 这样做时,我得到一个“圆形视图路径异常” . 这是由于百里叶视图解析器没有出现 . 一个简单的控制器方法如下所示: @Cacheable("Customers") @RequestMapping(value="/customer", method = RequestMethod.GET) public S... -
2 votesanswersviews
Spring Boot集成测试 - TestRestTemplate如何将响应Content-Type设置为UTF-8
我尝试集成测试Spring Boot应用程序,现在我遇到了一个问题 org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.ht... -
0 votesanswersviews
Spring创建错误,错误创建名为'entityManagerFactory'的bean
我在我的 spring boot (1.4.RELEASE) 应用程序中使用了两个 datasources . 当我运行gradle构建( ./gradlew clean build )时,它在 test task 中失败并出现以下错误: com.company.foo.ApplicationTests > contextLoads FAILED java.lang.Illegal...