首页 文章

运行JUnit集成测试STS中的Spring / JHipster

提问于
浏览
0

我有一个使用v3.4.0生成的Jhipster(使用Gradle) .

我正在尝试从STS运行和调试单元测试 .

从文档:

这些测试可以直接在IDE中运行,方法是右键单击每个测试类,或运行mvn clean test(如果运行Gradle,则运行./gradlew test) .

当gradle任务 $.gradlew test 按预期执行时,当我尝试"right click"和 Run As Junit TestDebug As Junit test时 - 我得到了数据库的异常:

堆栈跟踪的一小部分:

org.springframework.beans.factory.BeanCreationException:错误创建名为“org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration” beans :自动装配依赖注入失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor, java.util.List)抛出java.lang.Exception;嵌套异常是org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'securityConfiguration'的bean时出错:注入自动连接的依赖项失败;嵌套的例外是org.springframework.beans.factory.BeanCreationException:无法自动装配领域:私人org.springframework.security.core.userdetails.UserDetailsService web.myapp.core.config.SecurityConfiguration.userDetailsService;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'userDetailsService'的bean时出错:注入自动连接的依赖项失败;嵌套的例外是org.springframework.beans.factory.BeanCreationException:无法自动装配领域:私人web.myapp.core.repository.UserRepository web.myapp.core.security.UserDetailsService.userRepository;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建具有名称 beans “userRepository”:[org.springframework.orm.jpa.SharedEntityManagerCreator],同时设置 beans 无法创建内部bean类型的“(内部bean)#1c752902” property'entalManager';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'(内部bean)的bean#1c752902'时出错:在设置构造函数参数时无法解析对bean'entalManagerFactory'的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'entityManagerFactory'的bean时出错[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]:init方法的调用失败;嵌套异常是org.hibernate.cache.NoCacheRegionFactoryAvailableException:在应用程序中使用了二级缓存,但没有给出属性hibernate.cache.region.factory_class;请使用hibernate.cache.region.factory_class设置禁用二级缓存或设置正确的区域工厂,并确保类路径上有二级缓存提供程序(例如,hibernate-infinispan) .

我的假设是没有初始化测试数据库的正确配置文件: src/test/resources/application.yml

有关在STS中设置此配置文件的任何建议吗?

Update

我已根据https://jhipster.github.io/configuring-ide-eclipse-gradle/更新了一些屏幕商店:

  • No Resource Filters Project Properties > Resource > Resource Filters (none were added by STS when I imported the project
    No Resource Filters Project Properties > Resource > Resource Filters (none were added by STS when I imported the project

  • Checked to make sure the build/generated/source/apt/main is added to my Java Build Path settings under Project Properties > Java Build Path
    Checked to make sure the build/generated/source/apt/main is added to my Java Build Path settings under Project Properties > Java Build Path

1 回答

  • 1

    我遇到了同样的问题,这就是我的工作方式:
    1.作为gradle构建任务的一部分,您需要最初运行测试至少一次,然后才能使用JUnit以交互方式运行它
    2. JHipster默认生成build.gradle文件,仅运行名为* UnitTest或* IntTest的测试 . 如果你有这个默认配置,但是以不同的方式命名你的测试,那么上面的步骤1赢得't work because although the build may complete successfully it hasn' t实际上运行你的测试,因此它仍然无法在JUnit中运行 .
    3.按照上面添加的屏幕截图中给出的步骤作为原始问题的更新 .
    现在尝试以JUnit Test运行 .

相关问题