Grails 플러그인에서 자체 도메인 클래스로 작업하고 있습니다. 명명 된 데이터 소스를 사용하기 시작할 때까지 내 통합 테스트가 제대로 작동했습니다. 이제 테스트를 실행할 때마다 테스트에서 fixtureLoader.load()
을 호출 할 때마다 조명기 데이터가 데이터베이스에 복제됩니다.Grails 명명 된 데이터 소스를 사용할 때 조명기 데이터를 여러 번로드하는 테스트합니다.
Program.groovy :
package mydomain
class Program {
String name
String code
static mapping = {
datasource 'myData'
}
String toString() {
"$name ($code)"
}
}
programData.groovy : 여기
등등 내 도메인 객체 고정구의 일례이다import mydomain.*
fixture {
currentProg1(Program, name:'Program Name', code:'44')
}
내 데이터 소스과 같이 구성된 :
test {
dataSource_myData {
dbCreate = "create-drop"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
그리고 내 테스트는 다음과 같이이다 : 나는 테스트를 실행하면
package mydomain
import grails.plugin.spock.IntegrationSpec
class ProgramSpec extends IntegrationSpec {
def fixtureLoader
def "test current program list"() {
given:
def loader = fixtureLoader.load("programData")
when:
List results = Program.list()
then:
assert results.size() == 1
}
def "test toString"() {
given:
def loader = fixtureLoader.load("programData")
when:
def testCase = loader.currentProg1
then:
assert testCase.toString() == "Program Name (44)"
}
}
내가 얻을 :
Failure: test current program list(com.sg.contract.guide.ProgramSpec)
Condition not satisfied:
results.size() == 1
| | |
| 2 false
[Program Name (44), Program Name (44)]
내가 그것을 잘 작동 두 번째 테스트를 주석 처리합니다. 그러나 두 테스트를 모두 실행하면 조명기 데이터가 DB에 두 번 삽입됩니다.
데이터 소스를 변경하고 이름이 지정된 소스 (dataSource_myData
에서 dataSource
으로 변경)를 제거하고 내 도메인 클래스의 매핑에서 데이터 소스 구성을 제거하면 작동합니다.
이름이 지정된 데이터 소스로 인해 조명기 데이터가 두 번 삽입되거나 각 테스트 후에 정리되지 않는 이유를 모르겠습니다. 어떤 아이디어?
'spock' 통합 테스트에서'domain' 클래스를 인식 할 수없는 픽스처를 사용하여 문제를 재 작성/재 작성하는 데 문제가 있습니까? 빌드 - 테스트 - 데이터가 당신을위한 실행 가능 옵션이 아닌가? 어떤 Grails 버전을 사용하고 있습니까? – dmahapatro
build-test-data가 무슨 뜻인지 모르겠습니다. Grails 2.0.4을 사용하고 있습니다. – maximum
[build-test-data] (http://grails.org/plugin/build-test-data) 플러그인을 의미합니까? – dmahapatro