クラスで2つのspock
テストがあります。両方のテストのセットアップは同じです。
Class MySpec {
def "Test1"() {
setup:
def book = new Book(title: 'Something')
book.id = 1
book.save(flush: true, failOnError: true)
// rest of the test
}
def "Test2"() {
setup:
def book = new Book(title: 'Something')
book.id = 1
book.save(flush: true, failOnError: true)
// rest of the test
}
}
注:Book
ドメインには があるassigned
id
ため、保存時に明示的に設定する必要があります。
最初のテストは機能しますが、次のテストは で失敗しorg.springframework.dao.DuplicateKeyException
ます。テスト間でデータベースがロールバックされると思いました (このエラーは発生しないはずです)。ここで何が間違っていますか?