spring-test相关内容
我尝试通过链接. 我创建了RootTest.java @WebAppConfiguration @ContextConfiguration("file:src/test/resources/root-context2.xml") public class ReferenceServiceTest extends AbstractTestNGSpringContextTests { ..
..
我当前正在尝试加载SQL脚本来创建HSQL数据库. 这是通过使用以下代码完成的: Resource resource = new ClassPathResource("/create-table.sql"); SimpleJdbcTestUtils.executeSqlScript(template, resource, Boolean.FALSE); 该脚本包含触发器的
..
我有一个与单向相关的实体: @Entity public class Book { private String isbn; } @Entity private class Recommentation { @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "book_id
..
我正在使用带有H2的内存数据库来测试Dao.我正在将一个int传递给带有地图的查询以执行它.此查询在Oracle SQL上运行正常,但在H2中未成功. DAO @Override public int deleteCancelled(int days) { final Map namedParameters = new HashMap
..
我在数据层中有几个实体以特定的架构存储.例如: @Entity @Table(name = "FOO", schema = "DUMMY") public class Foo {} 我正在尝试设置H2嵌入式数据库,以对我的数据层进行集成测试. 我在测试中使用@DataJpaTest批注以自动配置H2嵌入式数据库.但是,表的创建失败,因为在数据库初始化时未创建架构DUMMY. 关于在
..
我正在Spring Boot项目中使用以下依赖项(在gradle中)以使其与mysql一起工作 compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootCloudVersion}") 并且在下面的我的application.properties文件中提供了数据源设置:- sprin
..
@ContextConfiguration 位置属性对于Spring Boot集成测试没有意义。还有其他方法可以在多个用 @SpringBootTest 注释的测试类中重用应用程序上下文吗? 解决方案 是。 实际上这是默认行为。链接指向Spring Framework文档,由Spring Boot在后台使用。 BTW,默认情况下,当同时使用 @ContextConfiguration
..
我使用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(
..
我的Spring Boot应用程序是这样启动的: new SpringApplicationBuilder() .sources(ParentCtxConfig.class) .child(ChildFirstCtxConfig.class) .sibling(ChildSecondCtxConfig.class) .run(args); Config类用@SpringB
..
据我了解,TestExecutionListeners的行为类似于JUnit中的@BeforeClass方法.我不明白的是为什么我需要使用DependencyInjectionTestExecutionListener,TransactionalTestExecutionListener和DirtiesContextTestExecutionListener来使用DbUnitTestExecuti
..
我正在尝试通过集成测试涵盖一个庞大的Spring Boot应用程序.应用程序中有很多Spring bean.加载Spring上下文需要一段时间. 所以我想知道- Spring是否足够聪明,可以在位于不同类中的多个集成测试之间共享相同的上下文?我的意思是避免为每个测试类初始化繁重的上下文. 当测试1,2,4使用TestContextOne而测试3,5使用TestContextTwo时会
..
根据 https://stackoverflow.com/a/33042872/4106030 我们不应该使用@Profile来让spring配置文件决定是应执行还是忽略测试类中的所有测试. 有记载: @Profile用于有选择地启用某个组件(例如,@Service等),@Configuration类或@Bean方法,如果其中一个命名的bean定义配置文件在Spring Environ
..
我有一个RepositoryRestController,它公开了一些持久实体的资源. 我的控制器上有一个方法,该方法采用PersistentEntityResourceAssembler来帮助我自动生成资源. @RepositoryRestController @ExposesResourceFor(Customer.class) @RequestMapping("/api/cust
..
我在尝试测试接收UserDetails作为用@AuthenticationPrincipal. 注释的参数的REST端点时遇到了麻烦 似乎没有使用在测试场景中创建的用户实例,而是尝试使用默认构造函数实例化:org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.andrucz.app.Ap
..
是否可以为通过MockMvc的所有请求(获取,发布,放置,删除)设置servlet路径? Spring分派servlet映射到/rest/* 但是在测试中,我必须删除url中的/rest部分,否则Spring测试无法识别控制器. 编辑 @Sotirios: 可能会发生以下情况: public class MyWebTests { private MockMv
..
@UsernameAlreadyExists private String username; 我创建了一个自定义验证器,以确保在提交帐户创建表单时,应用程序可以捕获重复的用户名. 当我使用MockMVC对帐户创建控制器进行单元测试时,由于验证程序依赖于服务,因此它失败,因此我得到了空指针异常. 如何模拟验证器或验证器所依赖的服务? 我无法弄清楚如何使它工作,因为控制器并不显式依赖
..
我有一个@SpringBootTest,并且我需要通过ApplicationEnvironmentPreparedEvent通知以创建数据库文件(如果该文件不存在),因为我的应用程序数据库尝试连接到该文件并且该文件不存在. 我是通过SpringApplicationBuilder来执行此操作的,但是在JUnit中,我无法访问此构建器.这是我当前的main代码: SpringApplic
..