gpt4 book ai didi

hibernate - grails IntegrationSpec:如何使其不回滚

转载 作者:行者123 更新时间:2023-12-02 15:06:31 26 4
gpt4 key购买 nike

我想在测试代码下面不要在测试完成后回滚。

我在mysql上插入了数据,但从未提交。

我使用了 @Rollback 和许多东西,但都没有成功。

测试代码如下。

import grails.test.spock.IntegrationSpec
import grails.transaction.Rollback;
import org.hibernate.SessionFactory
import spock.lang.*
import com.ms.domain.WordInSentence

class CompanyServiceSpec extends IntegrationSpec {

CompanyService companyService;

void "count login to private area"() {
setup:''
when:''
then:''
// def transaction = sessionFactory.currentSession.beginTransaction()
companyService.scoreCompany();
// transaction.commit()
}
}

服务类。
@Transactional
class CompanyService {

def dataSource;

void scoreCompany() {
WordInSentence wis = new WordInSentence()
wis.word = "a"
wis.location = 1;
wis.sentence_id = 1
wis.save(flush:true);
wis.save();
}
}

最佳答案

引用Grails Documentation

Integration tests run inside a database transaction by default, which is rolled back at the end of the each test. This means that data saved during a test is not persisted to the database. Add a transactional property to your test class to check transactional behaviour:

class MyServiceTests extends GroovyTestCase {
static transactional = false
void testMyTransactionalServiceMethod() {

}
}


这应该可以回答您的问题
...
class CompanyServiceSpec extends IntegrationSpec {

static transactional = false
...

关于hibernate - grails IntegrationSpec:如何使其不回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27705582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com