首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Unitils - Dbunit ExpectedDataSet失败/阻塞

Unitils - Dbunit ExpectedDataSet失败/阻塞
EN

Stack Overflow用户
提问于 2012-03-01 10:24:39
回答 1查看 1.3K关注 0票数 0

我正在使用Spring3.1.0.RELEASE和带有Hibernate提供者的JPA 2创建一个web应用程序。我正在使用junit 4.10、dbunit 2.4.8、unitils 3.3、hsqldb 2.2.8进行测试。

我试着测试服务层,一个创建操作。在我的刀中我有这样的方法:

代码语言:javascript
复制
@Override
    @Transactional
    public void createQuestion(Question question) {
        logger.debug("createQuestion");

        entityManager.persist(question);
        logger.info("New question created  [id] {}", question.getId());

    }

我的QuestionServiceTest测试课程:

代码语言:javascript
复制
@SpringApplicationContext("test-applicationContext.xml")
public class QuestionServiceTest extends UnitilsJUnit4 {

    @SpringBeanByName
    private QuestionService questionService;

    @SpringBeanByName
    private ThemeService themeService;

    @Test
    @DataSet("QuestionServiceTest.testCreateQuestion.xml")
    @ExpectedDataSet("QuestionServiceTest.testCreateQuestion-result.xml")
    public void testCreateQuestion() {
        final Question newQuestion = new Question();
        newQuestion.setCountryCode("FR");
        newQuestion.setEmail("test@mytest.com");
        newQuestion.setFirstName("FirstTest");
        newQuestion.setLastName("LastTest");
        newQuestion.setOriginalLang(LanguageEnum.FR);
        newQuestion.setOriginalQuestion("This is the original question");
        final Calendar calendar = Calendar.getInstance();
        calendar.set(2012, 5, 12);
        newQuestion.setCreationDate(calendar.getTime());
        final Theme theme = themeService.findThemeById(new Integer(1));
        newQuestion.setTheme(theme);
        questionService.createQuestion(newQuestion);
    }
}

我使用属性hibernate.hbm2ddl.auto =create来生成模式,问题表是:

代码语言:javascript
复制
create table question (
        id integer generated by default as identity (start with 1),
        country_code varchar(10) not null,
        creation_date timestamp not null,
        email varchar(255) not null,
        firstname varchar(100) not null,
        lastname varchar(100) not null,
        original_lang varchar(255) not null,
        original_question clob not null,
        theme_id integer not null,
        primary key (id)
    )

theme_id是表主题的外键。

当我用ExpectedDataSet启动测试时,插入可以工作,但是测试永远不会完成。测试块:

调试: org.dbunit.database.AbstractResultSetTable -查询:从“公开”中选择"ID“、"COUNTRY_CODE”、"CREATION_DATE“、"EMAIL”、"FIRSTNAME“、"LASTNAME”、"ORIGINAL_LANG“、"ORIGINAL_QUESTION”、"THEME_ID“。

这是调试的最后一行。

我的unitils.properties是:

代码语言:javascript
复制
# Defaults and other keys with explanations can be found there: http://unitils.org/unitils-default.properties
database.driverClassName=org.hsqldb.jdbcDriver
database.url=jdbc:hsqldb:mem:testOpen
database.userName=sa
database.password=
database.dialect=hsqldb

#  This schema is the initial schema when a new session is started in HSQLDB, don't change it or test won't works !
database.schemaNames=PUBLIC

dbUnit.datasetresolver.prefixWithPackageName=false
dbUnit.datasetresolver.pathPrefix=dataSets

我的persistence.xml:

代码语言:javascript
复制
<persistence-unit name="OpenTestPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
            <property name="hibernate.connection.username" value="sa" />
            <property name="hibernate.connection.password" value="" />
            <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:testOpen" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
    </persistence-unit>

我该怎么办?我已经尝试过以前发布的dbunit或unitils,但是它没有改变任何东西。预期的数据集确实是很酷的特性。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-09-20 13:05:14

我也有同样的问题,但没能解决。然后我尝试了一下spring测试-dbunit,这个库运行得很顺利。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9514460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档