|
I have been writing tests for my GLORP mappings and figure out at
least two options for preparing database:
1. Do the test's actions in transaction and rollback it at the end of
the test.
GlorpDirectMappingDBTest testUpdate
|newPerson |
self inTransactionDo: [
session beginUnitOfWork.
newPerson := GlorpPerson example1.
personId := newPerson id.
session register: newPerson.
session commitUnitOfWork.
session reset.
self readPerson.
session inUnitOfWorkDo: [
session register: person.
person name: 'something else'].
session reset.
self readPerson.
self assert: person id = newPerson id.
self assert: person name = 'something else'].
inTransactionDo: aBlock
[session beginTransaction.
aBlock value] ensure: [session rollbackTransaction].
2. Clean-up schema tables for each test.
testSaveExpert
| e query results |
e := Expert new.
e name: 'Vladimir'.
self session inTransactionDo: [
self session inUnitOfWorkDo: [
self session register: e
]
].
self session reset.
query := Query returningManyOf: Expert.
results := query executeIn: self session.
self assert: results size = 1.
e := results first.
self should: e name = 'Vladimir' description: 'Vladimir'.
setUp
super setUp.
self session: TestsGlorpSessionResource current newSession.
self session system recreateAllTables.
recreateAllTables
self session accessor dropTables: self allTables.
self createAllSequences.
self createAllTables
I was using first approach at the first time, but now migrate to
second because I think it seems more flexible and more real. I can
commit real transactions, and test that it saves to DB and retrieves
successfully. In first approach I am not really sure that writes had
been really done in database.
Also I'm not sure that first approach will always work with nested
transactions.
But I'm not still really sure that I should use second approach.
Who can make me sure in one of these approaches?
|