spring-test-mvc相关内容
我正在使用 Spring 的“spring-test-mvc"库来测试 Web 控制器.我有一个非常简单的控制器,它返回一个 JSON 数组.然后在我的测试中我有: @Test公共无效应该GetAllUsersAsJson()抛出异常{mockMvc.perform(get("/v1/users").accept(MediaType.APPLICATION_JSON)).andExpect(co
..
这是我在控制器中的方法,由 @Controller 注释 @RequestMapping(value = "/getServerAlertFilters/{serverName}/", 产生 = "application/json; charset=utf-8")@ResponseBody公共 JSONObject getServerAlertFilters(@PathVariable Str
..
我有简单的集成测试 @Testpublic void shouldReturnErrorMessageToAdminWhenCreatingUserWithUsedUserName() 抛出异常 {mockMvc.perform(post("/api/users").header("Authorization", base64ForTestUser).contentType(MediaType.
..
我正在尝试使用 SecurityConfig 类中定义的自定义安全设置来测试 @WebMvcTest: @Configuration@启用网络安全公共类 SecurityConfig 扩展了 WebSecurityConfigurerAdapter {@覆盖protected void configure(HttpSecurity http) 抛出异常 {http.authorizeReques
..
控制器 @RestController@验证类我的控制器{@GetMapping("/foo")public String unwrapped(@Min(1) @RequestParam("param") int param) {返回 Integer.toString(param);}@GetMapping("/bar")公共字符串包装(@ModelAttribute @Valid Wrappe
..
我使用嵌入式 Mongo DB 数据库按以下方式配置了 Spring 集成测试: @WebAppConfiguration@ContextConfiguration(classes = TpimApplication.class)//@SpringBootTest(classes=SPApplication.class)//@WebMvcTest(controllers = {Controlle
..
给定存储库 public interface ResourceRepository extends CrudRepository{ ... } 以下测试代码: @WebMvcTest@RunWith(SpringRunner.class)公共类 RestResourceTests {@自动连线私有 MockMvc mockMvc;@测试public void create_ValidReso
..
我在 Spring Boot 1.4 之前的 OAuth 集成测试如下(更新只是为了不使用已弃用的功能): @RunWith(SpringRunner.class)@SpringBootTest(classes = { ApplicationConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT)公共类 OAuth2I
..
这是我的 Spring Controller 测试用例 @RunWith(SpringRunner.class)@WebMvcTest(value = MyController.class)公共类 MyControllerTest {@MockBean私人 MyService myService;} 所以这是一个专门针对 MyController 中的方法的单元测试.但是当我运行测试时,Spr
..
我有一个简单的健康控制器,定义如下: @RestController@RequestMapping("/admin")公共类 AdminController {@Value("${spring.application.name}")字符串服务名称;@GetMapping("/health")字符串 getHealth() {返回服务名称 + "启动并运行";}} 以及测试它的测试类: @We
..
我在Kotlin中编写了一个非常简单且通用的CRUD.我想做基本测试,如测试发布,删除,获取和放置. 可能我理解错了:我使用Beforeeach的目的是插入一个寄存器,以便可以在get测试期间进行检查.我没有收到异常,但似乎在进行get测试时,如果波纹管测试中的其他id不同于1,则它总是NOT_FOUND时总是返回ok. 即使根据我的目的(简单的CRUD测试)看到其他不好的做法,任何朝
..
我正在开发一个具有一定数量控制器的Spring Boot MVC应用程序. 我的根控制器是: @Controller @RequestMapping("/") public class RootController { @GetMapping public String showStartPage() { log.info("GET: Show home p
..
我正在Java 7上使用Spring 4.3.18和Spring Boot 1.5.14. 我正在实现RestController端点,该端点返回带有超时回调的DeferredResult.我正在尝试为超时回调编写单元测试,但无法获得MockMvc单元测试来调用超时回调. 为了测试,我写了这个端点: @PostMapping("/test") public DeferredRes
..
我正在为Spring Rest Service编写测试,该测试将URL重定向到另一个spring服务.因此,目标是使用书签名称查找“书签".第一个服务使用书签名称获取BookmarkId,然后根据BookmarkId重定向URL以加载对象 我可以轻松地使用来测试url重定向,以下工作正常 mockMvc.perform(get("/bookmarks/name/" + "sample
..
我尝试为一个简单的spring-boot控制器创建我的第一个测试,但得到Handler: Type = null.在浏览器中,代码有效,但测试失败.我的应用程序使用spring-security.请帮助我解决问题并了解我的错误.谢谢. 这是控制者: private final ItemService service; @GetMapping("/get_all_items") pub
..
我使用Spring Boot创建文件上传服务,并使用Spring Mock Mvc和MockMultipartFile对其进行测试.我想测试超过最大文件大小时是否引发错误.以下测试失败,因为它收到200. RandomAccessFile f = new RandomAccessFile("t", "rw"); f.setLength(1024 * 1024 * 10); InputStre
..
我正在使用MockMvc编写集成测试,我想知道是否存在一种从web.xml加载servlet映射的方法(通常不重要). 我有一个自定义HandlerInteceptor,该自定义HandlerInteceptor将请求URI(来自HttpServletRequest)与模板(使用AntPathMatcher)进行匹配. 在web.xml中,我定义了这样的servlet映射(以及相应的m
..
我试图用Spring Security和Thymeleaf为视图层编写Spring MVC集成测试. 我已经使用Spring Security Integration设置了我的MockMvc对象,就像文档中的所有示例一样. 集成测试设置: import static org.springframework.security.test.web.servlet.setup.Secur
..
我在Spring MVC中有一个带有可选path变量的方法.我正在尝试在未提供可选路径变量的情况下对其进行测试. 来自控制器的片段,要调用的资源URI- @RequestMapping(value = "/some/uri/{foo}/{bar}", method = RequestMethod.PUT) public ResponseEntity someMethod(
..
是否可以使用JsonPath计算成员数量? 使用 spring mvc测试我正在测试生成控制器 {"foo": "oof", "bar": "rab"} 使用 standaloneSetup(new FooController(fooService)).build() .perform(get("/something").accept(MediaTyp
..