Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 弹簧控制器测试。Can';我好像找不到冒牌货_Unit Testing_Spring Mvc_Junit_Integration Testing_Spring Test Mvc - Fatal编程技术网

Unit testing 弹簧控制器测试。Can';我好像找不到冒牌货

Unit testing 弹簧控制器测试。Can';我好像找不到冒牌货,unit-testing,spring-mvc,junit,integration-testing,spring-test-mvc,Unit Testing,Spring Mvc,Junit,Integration Testing,Spring Test Mvc,我正在尝试为我的Spring控制器编写一些单元和集成测试 问题是我无法在mvnrepository中为下面的代码段找到合适的include this.mockMvc.perform(get("/foo").accept("application/json")) .andExpect(status().isOk()) .andExpect(content().mimeType("application/json")); 我找不到get(“/foo)方法和.mim

我正在尝试为我的Spring控制器编写一些单元和集成测试

问题是我无法在mvnrepository中为下面的代码段找到合适的include

 this.mockMvc.perform(get("/foo").accept("application/json"))
        .andExpect(status().isOk())
        .andExpect(content().mimeType("application/json"));
我找不到get(“/foo)方法和.mimeType(..)的jar

谷歌搜索之后,我找到了上面的get和mimeType的源代码。 那么,我应该从这个Spring测试展示项目中复制粘贴这些帮助程序类吗?还是我在这里遗漏了什么

 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>

org.springframework
弹簧试验
${spring.version}

在pom.xml中的某个地方?

我假设您使用的是EclipseIDE。不幸的是,它不会自动导入静态导入

您必须通过以下方式添加这些内容:窗口>首选项>Java>编辑器>内容辅助>收藏夹

这里有一篇包含更多信息的好帖子:

在spring test中,包名似乎从
test.web.server
更改为
test.web.servlet
,博客文章/文档在spring 4中已过期。

确保导入是静态的。导入static org.springframework.test.web.server.request.MockMvcRequestBuilders.get;@Sparticles因此我尝试输入这些统计信息c导入,但IDE似乎无法找到它(本地或在Maven repo中)。这是否意味着我需要手动将这些静态类复制到我的项目中?这感觉不对!如果您缺少JAR,这里是maven repo的链接,请下载相应的链接并将其添加到您的库中。@Sparticles我确实包含spring测试依赖项。我需要的是MockHttpServletRequestBuilderTests.java,它是nspring测试jar中的ot。什么是spring版本?如果我没有弄错的话,这个功能需要3.2+。是的。我确实包含了spring测试依赖项。我在这里需要的是MockHttpServletRequestBuilderTests.java,它不在spring测试jar中。如果您在pom.xmlexactly中指定了依赖项,就不应该强制您手动添加任何内容!这就是为什么我要这么做的原因我很困惑。那么,也许你的依赖关系有些混乱。看看有效的pom,它可能会给你一些线索。这是答案。请标记它。