【问题标题】:JUnit Test not rollbacking with SpringJUnit4ClassRunnerJUnit 测试不使用 SpringJUnit4ClassRunner 回滚
【发布时间】:2016-01-29 22:37:34
【问题描述】:

为了正确看待事情,一切正常,直到我不得不格式化我的工作站。在我设法让项目运行之后,我运行了 JUnit 测试并且我的大部分测试都失败了。问题是因为数据库没有回滚。也许我错过了一些配置,也许是 mysql 它自己。

所以,这些是我的配置/源文件:

一个 JUnit 类声明:

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

测试范围的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>

【问题讨论】:

    标签: java mysql junit


    【解决方案1】:

    检查您为应用程序表使用的引擎。 MyISAM 不支持事务。你应该使用 InnoDB。

    要检查引擎,请使用查询:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 2017-03-13
      • 1970-01-01
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多