运行 STS 中的 JUnit 集成测试 Spring/JHipster
Running JUnit Integration Tests Spring/JHipster in STS
我有一个使用 v3.4.0 生成的 Jhipster(使用 Gradle)。
我正在尝试 运行 并从 STS 调试单元测试。
来自文档:
Those tests can be run directly in your IDE, by right-clicking on each
test class, or by running mvn clean test (or ./gradlew test if you run
Gradle).
虽然 gradle 任务 $.gradlew test
按预期执行,但当我尝试 "right click" 和 Run As Junit Test
或 Debug As Junit
测试时 - 我在数据库:
堆栈跟踪的一小部分:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration':
Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire method: public void
org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List)
throws java.lang.Exception; nested exception is
org.springframework.beans.factory.BeanExpressionException: Expression
parsing failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'securityConfiguration': Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private
org.springframework.security.core.userdetails.UserDetailsService
web.myapp.core.config.SecurityConfiguration.userDetailsService;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'userDetailsService': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private web.myapp.core.repository.UserRepository
web.myapp.core.security.UserDetailsService.userRepository; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'userRepository': Cannot create inner
bean '(inner bean)#1c752902' of type
[org.springframework.orm.jpa.SharedEntityManagerCreator] while setting
bean property 'entityManager'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name '(inner bean)#1c752902': Cannot resolve
reference to bean 'entityManagerFactory' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'entityManagerFactory' defined in class path
resource
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]:
Invocation of init method failed; nested exception is
org.hibernate.cache.NoCacheRegionFactoryAvailableException:
Second-level cache is used in the application, but property
hibernate.cache.region.factory_class is not given; please either
disable second level cache or set correct region factory using the
hibernate.cache.region.factory_class setting and make sure the second
level cache provider (hibernate-infinispan, e.g.) is available on the
classpath.
我的假设是测试数据库的正确配置文件未初始化:src/test/resources/application.yml
关于在 STS 中设置此配置文件的任何建议?
更新
我已经根据 https://jhipster.github.io/configuring-ide-eclipse-gradle/:
更新了一些屏幕商店
没有资源过滤器Project Properties > Resource > Resource Filters
(none是我导入项目时STS添加的
检查以确保 build/generated/source/apt/main
已添加到 Project Properties > Java Build Path
下的 Java 构建路径设置中
我遇到了同样的问题,这就是我的工作方式:
1. 作为 gradle 构建任务的一部分,您需要首先 运行 测试至少一次,然后才能 运行 它与 JUnit
交互
2. JHipster 生成 build.gradle 文件默认只包含 运行 名为 *UnitTest 或 *IntTest 的测试。如果您有这个默认配置,但以不同的方式命名您的测试,那么上面的步骤 1 将不起作用,因为虽然构建可能成功完成,但它实际上并没有 运行 您的测试,因此它仍然不能在 JUnit 中是 运行。
3. 按照上面添加的屏幕截图中给出的步骤作为对原始问题的更新。
现在尝试 运行ning 作为 JUnit 测试。
我有一个使用 v3.4.0 生成的 Jhipster(使用 Gradle)。
我正在尝试 运行 并从 STS 调试单元测试。
来自文档:
Those tests can be run directly in your IDE, by right-clicking on each test class, or by running mvn clean test (or ./gradlew test if you run Gradle).
虽然 gradle 任务 $.gradlew test
按预期执行,但当我尝试 "right click" 和 Run As Junit Test
或 Debug As Junit
测试时 - 我在数据库:
堆栈跟踪的一小部分:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService web.myapp.core.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private web.myapp.core.repository.UserRepository web.myapp.core.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#1c752902' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1c752902': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
我的假设是测试数据库的正确配置文件未初始化:src/test/resources/application.yml
关于在 STS 中设置此配置文件的任何建议?
更新
我已经根据 https://jhipster.github.io/configuring-ide-eclipse-gradle/:
更新了一些屏幕商店没有资源过滤器
Project Properties > Resource > Resource Filters
(none是我导入项目时STS添加的检查以确保
build/generated/source/apt/main
已添加到Project Properties > Java Build Path
下的 Java 构建路径设置中
我遇到了同样的问题,这就是我的工作方式:
1. 作为 gradle 构建任务的一部分,您需要首先 运行 测试至少一次,然后才能 运行 它与 JUnit
交互
2. JHipster 生成 build.gradle 文件默认只包含 运行 名为 *UnitTest 或 *IntTest 的测试。如果您有这个默认配置,但以不同的方式命名您的测试,那么上面的步骤 1 将不起作用,因为虽然构建可能成功完成,但它实际上并没有 运行 您的测试,因此它仍然不能在 JUnit 中是 运行。
3. 按照上面添加的屏幕截图中给出的步骤作为对原始问题的更新。
现在尝试 运行ning 作为 JUnit 测试。