问题标签 [springjunit4classrunner]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
spring-boot - 无法在 Spring Boot 项目中使用 SpringJUnit4ClassRunner 运行 powermockrule
我有一个 spring boot 项目,需要使用 spring test runner 进行测试(以便我可以获得真正的应用程序上下文)并模拟静态方法。
运行测试时收到以下错误消息:
如何解决这个问题?谢谢!
java - 如何在一次测试中测试多个 Spring Boot 应用程序?
我有一个带有 2 个 Spring Boot 应用程序的多模块 Maven 项目
父母
- fooApp
- 酒吧应用
- 测试
如何设置一个测试,您可以在同一过程中加载单独的 Spring Boot 应用程序,每个应用程序都有自己的配置上下文。
和一个集成测试的例子
spring - 无法为 Spring 应用程序运行一些单元测试
春季新手来了。尝试将各种在线春季教程融合到一个工作项目中。从这个链接中描述的 spring mvc 教程开始。
现在我正在尝试将这个关于 Spring data jpa 的在线教程融合到上述项目中。正如您在附图中看到的那样,我已经添加了所有必要的项目文件(src、test、.xml 文件等)。
我的问题是,当我执行 mvn package (这是我一直用来构建和运行测试的方法)时,第二个项目的新测试套件没有得到执行。我想知道为什么!在不提供所有资源的情况下,我将展示一些最重要的配置 (.xml) 文件。
图片显示添加的新文件、现有文件和问题的简要说明:
注意:抱歉,stackoverflow 正在删除一些 xml 元数据。它们主要是导入 xml 定义的标题标签,因此并不那么重要。
orm.xml(为 spring-data-jpa 练习添加)
persistence.xml(为 spring-data-jpa 练习添加)
http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd" version="2.1">
root-context.xml(最初用于 spring-mvc-tutorial)
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4.) controllers.xml, 5.)servlet-context.xml 文件只是将控制器映射到路径、定义和实例化 dispatcher-servlet 以及其他已经在 spring-mvc-tutorial 代码中的 bean 的标准文件。我相信他们与这张票中描述的问题没有任何关系。
这是不执行的测试文件,我想运行:
任何帮助深表感谢!
java - 使用新的 Spring Context 开始 JUnit 测试
我使用JUnit4
. 它们都单独运行良好,但一个接一个地运行它们(例如通过 mvn 测试),第二个测试失败。
第二个测试失败的原因是第一个测试在第一个测试中修改了一个 bean。第二个测试想要使用这个 bean 的新实例。
单元测试应该为每个单元测试类赋予一个新的上下文。Spring 对我想禁用的上下文缓存具有一流的支持。如何配置为每个单元测试类Spring
重新启动一个新的?Context
我的测试类配置如下:
java - 移动或删除类后使用 SpringJUnit4ClassRunner 运行 junit 测试的初始化错误
通常,当我移动或删除一个类时,我在移动或删除一个类后使用 SpringJUnit4ClassRunner 运行 junit 测试时遇到初始化错误。
例外:
我的测试类看起来像:
我用 gradle task cleanTest test运行我的测试
我试图使 IntelliJ 缓存无效并重新启动它没有帮助。
我怎么能摆脱这个异常?
java - 为什么在使用 @RunWith(SpringJUnit4ClassRunner.class) 时 JUnit 4.12 会为 assertEquals 抛出 NoSuchMethodError?
最近我们的一个 web 服务的变化增加了在我们的测试中使用自动装配 bean 的要求,但是,我无法获得每个人都建议工作的 @RunWith(SpringJUnit4ClassRunner.class) 路由。当我将该注释添加到我的类时,我收到了 assertEquals 方法的“NoSuchMethodError”。
pom.xml 依赖项:
正在测试的方法:
测试类:
堆栈跟踪:
spring - Junit spring/jersey 测试不通过@Transaction 提交查询
我有以下测试代码
这个想法是我在每次测试运行时使用 SQL 查询手动清理数据库。我有一堆 @Test 方法在表 location_group 中运行和生成行。
不幸的是,当我查看我的数据库时,没有任何内容被删除。知道为什么即使“已删除”表示删除了许多行,实际上什么也没删除?
spring - Cannot setup Mock Class in Spring
I'm coming onto a project that a suite of Integration tests. One of these tests autowired a class that did a lot of network calls to a 3rd party vendor. Because we didn't want our tests to make these calls, the team mocked out this client via a testApplicationContext.xml Spring configuration file.
Integration Test Class:
Definition of testApplication.xml:
Definition of mock-beans.xml:
This works fine in our setup and an instance of MockThirdPartyClient is autowired into our spring bean when run as a test.
However, I added a new mock for another service recently, in the same package, but cannot get it to load. I get the error:
Cannot find class [tst.mycompany.mocks.MockAdressService] for bean with name 'addressService' defined in class path resource [mock-beans.xml]; nested exception is java.lang.ClassNotFoundException: tst.mycompany.mocks.MockAdressService
Here is the updated mock-beans.xml:
Here's how I autowire the initial dependency that works:
@Autowired ThirdPartyClientServiceI client;
and the one that doesn't:
@Autowired AddressServiceI addressService;
I've double checked the spelling on everything and it all lines up so it's crazy that this isn't working. I thought maybe it was a case of something being cached incorrectly... but I refreshed and cleaned everything and still no dice.
Neither of these mocks has annotations FWIW, they just implement the Interface of the service they're designed to mock out. They are both located underneath the src/test/java
folder.
the stacktrace in question:
I did check the bin folder and the compiled class is there.
spring - 为什么在 Spring Boot 应用程序的 Junit 测试中无法使用 appliction.properties 的属性?
我有一个弹簧启动应用程序。我正在编写 Junit 测试。我正在尝试从 application.properties(在 src/main/resources/application.properties 中定义)和 AppConfig 中配置的 Status bean(src/main/java/hello/AppConfig.java)注入值。我看到 bean 是自动装配的(通过调试器它不为空),但未设置值。
这是 application.properties
src/main/resources/ application.properties
src/main/java/hello/AppConfig.java
//Status 是一个简单的 pojo,带有 name 和 version 字段
src/test/java/hello/GreetingControllerTests.java
我在 init 方法中设置了调试器,发现设置了正确值的 beanappName
和bean 都没有被注入。status
虽然注入了状态 bean。只是没有设置值。
junit - DBunit 数据在 Oracle 中不可见
在我的项目中,我们使用 xml 文件将数据插入数据库(oracle)。但是,我没有得到这些数据在 DB 中的插入位置。我在执行查询时看到插入语句。但数据在数据库中不可见。检索时,数据来自数据库。但是这些数据存储在数据库中的位置。它使用任何临时表将数据存储在 DB 或它使用的任何其他机制中。我在执行插入查询语句时调试了代码。插入查询语句执行成功。但是数据在数据库中不可见。
如果有人对此有想法,请向我解释。