gpt4 book ai didi

grails - Grails IntegrationSpec IllegalStateException

转载 作者:行者123 更新时间:2023-12-02 13:51:38 25 4
gpt4 key购买 nike

从2.4.0升级到2.4.2后,运行集成测试时出现错误。它显示测试已通过,但是我收到了IllegalStateException。

    Failure:  |
massemailsystem.UserInformationIntegrationSpec
|
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)

我试图分析测试,但没有发现任何异常。这是完整的测试。我正在测试从LDAP数据源获取信息
abstract class DirectoryIntegrationSpec extends IntegrationSpec {

DirContextOperations getContext(Map attrs) {
DirContextAdapter d = new DirContextAdapter()
attrs.each { k, v ->
if (v != null) {
d.addAttributeValue(k, v)
}
}
d
}
}


class UserInformationIntegrationSpec extends DirectoryIntegrationSpec {

def dataSource

def setup() {
new SPRIDEN(pidm: 100, yNumber: 'Y00100', lastName: 'Smith').save(flush: true, failOnError: true)
new SPBPERS(pidm: 100, prefFirstName: 'Joe', activityDate: new Date(), armedServMedVetInd: 'N').save(flush: true, failOnError: true)
new SPRTELE(pidm: 100, seqNo: 1, teleCode: 'CE', activityDate: new Date(), primaryInd: 'Y', phoneArea: '330', phoneNumber: '1234567').save(flush: true, failOnError: true)

new SPRIDEN(pidm: 102, yNumber: 'Y00102', lastName: 'Smith').save(flush: true, failOnError: true)
new SPRTELE(pidm: 102, seqNo: 1, teleCode: 'CE', activityDate: new Date(), primaryInd: 'Y', phoneArea: '330', phoneNumber: '1234567').save(flush: true, failOnError: true)

new SPRIDEN(pidm: 103, yNumber: 'Y00103', lastName: 'Smith').save(flush: true, failOnError: true)
}

def cleanup() {
}

@Unroll
void "test constructor from LDAP for fake #employeeid"() {
when:
def context = getContext([employeeid: employeeid, givenname: firstName, sn: lastName, mail: email])
UserInformation u = new UserInformation(context, username, dataSource)

then:
u.id == id
u.firstName == prefFirstName
u.lastName == lastName
u.email == email
u.phone == phone
u.department == department
u.username == username

where:
employeeid | username | id | firstName | prefFirstName | lastName | email | phone | department
'Y00100' | 'jsmith' | 100 | 'Joseph' | 'Joe' | 'Smith' | 'jsmith@ysu.edu' | '(330) 123-4567' | null
"Y00101" | null | null | null | null | null | null | null | null
"Y00102" | 'jsmith' | 102 | 'Joseph' | 'Joseph' | 'Smith' | 'jsmith@ysu.edu' | '(330) 123-4567' | null
"Y00103" | 'jsmith' | 103 | 'Joseph' | 'Joseph' | 'Smith' | null | null | null
}
}

提前致谢!

编辑:当我自己运行它时,测试不会失败,只有当我运行所有集成测试时。

最佳答案

我这边的愚蠢问题。

测试之前的测试是使用@TestFor批注,并在应该扩展Specification而根本没有批注的情况下扩展IntegrationSpec。我将此规格从单位更改为集成,但未能更改这些内容。

有趣的是,测试本身运行良好,只有在出现问题后才进行测试。

关于grails - Grails IntegrationSpec IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24957901/

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