[英]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.