问题描述
从2.4.0升级到2.4.2后,当我运行集成测试时出现错误。它显示测试通过,但是我得到一个IllegalStateException。 失败:|
massemailsystem.UserInformationIntegrationSpec
|
java.lang.IllegalStateException:无法找到ApplicationContext,首先在grails.util.Holders.getApplicationContext(Holders.java:97)处首先
正确配置Grails:grails.test.spock.IntegrationSpec处
。$ spock_initializeSharedFields(IntegrationSpec.groovy:41)
我试着分析测试,看到任何不寻常的东西。继承人全面测试。我测试从LDAP数据源获取信息
抽象类DirectoryIntegrationSpec扩展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)
新SPRTELE(pidm:100,seqNo:1,teleCode:'CE',activityDate:new Date(),primaryInd:'Y',phoneArea:'' 330',phoneNumber:'1234567')。save(flush:true,failOnError:true)
$ b $ new SPRIDEN(pidm:102,yNumber:'Y00102',lastName:'Smith')。save flush:true,failOnError:true)
新SPRTELE(pidm:102,seqNo:1,teleCode:'CE',activityDate:new Date(),primaryInd: y',phoneArea:'330',phoneNumber:'1234567')。save(flush:true,failOnError:true)
SPRIDEN(pidm:103,yNumber:'Y00103',lastName:' Smith')。save(flush:true,failOnError:true)
}
def cleanup(){
}
@Unroll
void从LDAP伪测试构造函数伪造#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 ==电子邮件
u.phone ==电话
u.department ==部门
u.username ==用户名
其中:
employeeid |用户名| id | firstName | prefFirstName | lastName |电子邮件|电话|部门
'Y00100'| 'jsmith'| 100 | '约瑟'| '乔'| '史密斯'| '[email protected]'| '(330)123-4567'| null
Y00101| null | null | null | null | null | null | null | null
Y00102| 'jsmith'| 102 | '约瑟'| '约瑟'| '史密斯'| '[email protected]'| '(330)123-4567'| null
Y00103| 'jsmith'| 103 | '约瑟'| '约瑟'| '史密斯'| null | null |
$ / code $ / pre
预先感谢!
编辑:当我运行它自己时,测试不会失败,只有当我运行所有集成测试时。
解决方案
测试之前的测试是使用 @TestFor
code>注释并扩展规范
,当它应该扩展 IntegrationSpec
并且根本没有注解。我把这个规范从一个单元改成了一个集成,我没能改变这些东西。
有趣的是测试本身运行良好,只有在测试之后才进行测试一个问题。
After upgrading to 2.4.2 from 2.4.0, I am getting an error when I run my integration tests. It shows that the tests passed, however I am getting an 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)
I tried to analyze the tests and I don't see anything out of the ordinary. Heres the full test. I am testing getting information from an LDAP data source
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' | '[email protected]' | '(330) 123-4567' | null
"Y00101" | null | null | null | null | null | null | null | null
"Y00102" | 'jsmith' | 102 | 'Joseph' | 'Joseph' | 'Smith' | '[email protected]' | '(330) 123-4567' | null
"Y00103" | 'jsmith' | 103 | 'Joseph' | 'Joseph' | 'Smith' | null | null | null
}
}
Thanks in advance!
EDIT: The test doesn't fail when I run it by itself, only when I run all of my integration tests.
解决方案 Stupid problem on my end here.
The test right before the test was using the @TestFor
annotation and extending Specification
when it should have been extending IntegrationSpec
and not had the annotation at all. I changed this spec from a unit to an integration and I failed to change these things.
What was funny was the test itself worked fine, only tests that ran after it had a problem.
这篇关于Grails IntegrationSpec IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-07 00:32