私はいくつかのデータベースの内容を変更するスポーク/スプリングテストを持っており、そのレコードをどのようにロールバックするのだろうかと思います。テスト後に特定のレコードをロールバックする方法はありますか?
現在、私は生のSQL文を実行し、フィールドのデータを保存し、そのデータを正常にテストした後に復元します。しかし、私の推測は、これは簡単な方法で行うことができるということですか?テストを実行する前に
@ContextConfiguration(locations = "classpath*:applicationContext-test.xml")
class RepositoryTest extends Specification {
@Shared sql = Sql.newInstance("jdbc:sqlserver://...")
ResourceRepository resourceRepository;
def "Save test"() {
setup:
// copy the row before we do changes! we need to restore this later on!
def row = sql.firstRow("select id, content, status from table-name where id = 12345")
when:
...
then:
..
cleanup:
sql.execute("""
update table-name set content = ${row.content}, status = ${row.status}
where id = ${row.id}
""")
}
}
あなたが本当にむしろ試験方法がなかった何よりも、特定のレコードをロールバックしたいですか? –