简体   繁体   English

JUnit Test无法使用SpringJUnit4ClassRunner回滚

[英]JUnit Test not rollbacking with SpringJUnit4ClassRunner

To put things in perspective, everything was working fine untill I had to format my working station. 为了正确看待事情,一切正常,直到我必须格式化工作站。 After I've managed to get the project running I ran the JUnit tests and most of my tests broke. 在设法使项目运行之后,我运行了JUnit测试,并且我的大多数测试都失败了。 The problem was because the database is not rolling back. 问题是因为数据库没有回滚。 Maybe I missed on some configuration, maybe on mysql it self. 也许我错过了一些配置,也许是在mysql本身上。

So, these are my configuration/source files: 因此,这些是我的配置/源文件:

A JUnit Class declaration: JUnit类声明:

@ContextConfiguration(locations = { "classpath*:testApplicationContext.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class ClientServiceTest {

The applicationContext for test scope: 用于测试范围的applicationContext:

<bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${driver}"/>
    <property name="url" value="${url}"/>
    <property name="username" value="${user}"/>
    <property name="password" value="${password}"/>
    <property name="defaultAutoCommit" value="false" />

    </bean>

Check what engine you use for application tables. 检查用于应用程序表的引擎。 MyISAM does not support transactions. MyISAM不支持交易。 You should use InnoDB. 您应该使用InnoDB。

To check engine, use query: 要检查引擎,请使用查询:

SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'your_database_name'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用SpringJUnit4ClassRunner的Junit TestSuite - Junit TestSuite with SpringJUnit4ClassRunner 如何使用 SpringJUnit4ClassRunner 将映射器(mapstruct)注入 Junit 测试 - How to inject mapper (mapstruct) to Junit test with SpringJUnit4ClassRunner 如何使用Parametrized运行JUnit SpringJUnit4ClassRunner? - How to run JUnit SpringJUnit4ClassRunner with Parametrized? 将junit侦听器添加到SpringJUnit4ClassRunner - Add a junit listener to a SpringJUnit4ClassRunner SpringJUnit4ClassRunner是否为每个测试初始化​​bean? - SpringJUnit4ClassRunner initialize beans for each test? SpringJUnit4ClassRunner在JUnit测试用例结束时不关闭Application Context - SpringJUnit4ClassRunner does not close the Application Context at the end of JUnit test case 初始化错误在移动或删除类后使用SpringJUnit4ClassRunner运行junit测试 - initializationError running junit test with SpringJUnit4ClassRunner after moving or deleting a class 如何将SpringJUnit4ClassRunner的&#39;spring 3.1&#39;面向junit4测试转换为基于spring的junit3.8测试? - How can I turn this 'spring 3.1' oriented junit4 test with SpringJUnit4ClassRunner into a spring oriented junit3.8 based test? java sbt test:如果使用SpringJUnit4ClassRunner运行测试,则忽略异常 - java sbt test: exception ignored if test is run with SpringJUnit4ClassRunner SpringJUnit4ClassRunner是否为每个Test或Class加载了Context? - Did SpringJUnit4ClassRunner load the Context for every Test or for Class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM