首页 > TAG信息列表 > spring-boot-test

java-MockMvc,RestAssured和TestRestTemplate有什么区别?

就我所知,MockMvc只是测试Controller,并模拟Service层. RestAssured和TestRestTemplate正在测试我们API的运行实例. 那是对的吗? RestAssured和Spring Boot的TestRestTemplate有什么区别?解决方法:MockMvc是弹簧测试中的类之一.这主要用于控制器层的单元测试.不只是您的控制器类.这是

java-具有MockMvcBuilders独立设置的SpringBootTest尽管设置了它却没有加载我的ControllerAdvice

我正在创建这样的控制器和控制器建议: 测试类别: @RunWith(SpringRunner.class) @SpringBootTest public class TestController { private MockMvc mockMvc; @Mock private MyService myService; @Autowired @InjectMocks private MyController myContro

java-春季启动-应用程序启动两次..?

我是Spring Boot的新手,我的应用程序具有带有eh-cache模块的Servlet. @EnableCaching @SpringBootApplication @ServletComponentScan public class Application extends SpringBootServletInitializer { private static final Logger log = LoggerFactory.getLogger(Appli

java-Spring Boot:如何在单元测试中覆盖默认属性

我尝试为单元测试加载第二个属性文件, 那会覆盖一些属性. 在@Configuration上使用@PropertySource加载它无效,用@TestPropertySource加载它也不起作用.仅在@TesPropertySource上直接设置属性有效,但是当我尝试将其添加为元注释时,它不起作用. 这是一个示例项目:https://github.com/c

java – Spring Boot:自定义属性配置和测试

我正在使用Spring Boot 2.0和默认的application.yml属性文件.我想将它拆分为单独的属性文件,因为它变得很大. 此外,我想编写测试来检查属性的正确性:将出现在生产应用程序上下文中的值(而不是测试中的值). 这是我的属性文件:src / main / resources / config / custom.yml my-proper

java – @Value(“${local.server.port}”)无法在Spring boot 1.5中运行

我正在将Spring Boot从1.3升级到1.5.升级到1.5我已经更换了 @SpringApplicationConfiguration(classes = TestConfig.class)  @WebIntegrationTest 同 @SpringBootTest(classes = TestConfig.class) 另外,我正在使用 @Value( “${} local.server.port”) protected int port; 获

java – Spring Boot Unit测试未检测到自动装配组件的模块

我们将基于Maven的Spring Boot项目拆分为两个模块,如下所示: ProjectRoot -SharedModel -Application --main ---java ----com....(Application.java) -----com....(ClassToAutowire.java) --test ----com....(ApplicationTest.java) -----com....(ClassToAutowireTest.java) 测试

spring – @AutoConfigureWebMvc和@AutoConfigureMockMvc之间有什么区别?

在哪种情况下我应该使用每一个?解决方法:@AutoConfigureWebMvc Use this if you need to configure the web layer for testing but don’t need to use MockMvc 它启用与Web层相关的所有自动配置,并且仅启用Web层.这是整体自动配置的子集. 它包括以下自动配置(参见spring.fac

使用Multi Maven项目安装程序测试Spring Boot应用程序的问题

我目前遇到弹簧启动和多个maven项目结构的一些问题.我使用的是Spring Boot 4.3.1. 我的项目结构如下: parent -- pom.xml -- application -- pom.xml -- src -- main -- java -- Application.java (annotated with @SpringBootApplication)

java – 如何在spring test中动态设置环境变量

我正试图用spring-boot运行弹簧测试案例.我的测试类如下所示 @ContextConfiguration(initializers = TestContextInitializer.class) @RunWith(SpringRunner.class) @SpringBootTest(classes = {TestServiceApplication.class}) public class SampleTest { @org.junit.Test

java – Spring Boot 2.0 JNDI属性值未从application-test属性文件加载

我正在尝试运行在application-test.properties文件中配置的测试用例和jndi属性 @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = { App.class }, webEnvironment = WebEnvironment.RANDOM_PORT) @ContextConfiguration @TestPropertySource("classpath:/appli