Test fixtures or equivalent for test data with Smalltalk Berth?

I use Test Driven Development in the Seaside application I played with, and all my data is stored as objects in the image (as opposed to the database).

Therefore, when I run my tests, I had to be careful to store real data before it is broken by test data, for example:

ToDoTest>>setUp 
    savedTasks := Task tasklist.
    Task deleteAllTasks.

    savedProjects := ToDoProject projectlist.
    ToDoProject deleteAllProjects.

    savedPeople := Person peoplelist.
    Person deleteAllPeople.

and

ToDoTest>>tearDown
    Task tasklist: savedTasks.
    ToDoProject projectlist: savedProjects.
    Person peoplelist: savedPeople

The problem occurs when my tests fail, which of course they do, a debugger pops up, and I can fix it, but tearDown does not always cause a call, and therefore I can lose my real data.

I save the data in files, so this is not a huge problem, but it is not as smooth and automated as we would like.

Anyway, can I improve this?

+5
2

, , . , . , . - , , .

, : -. , "", - , . , .

TestCase → # runCase -

runCase
   [ self saveRealModel.
      super runCase ]
      ensure: [ self restoreRealModel ]
+6

, . , , , , . . StoryBoard

DEUser subclass: #SBUser
    instanceVariableNames: 'email initials projects invitations'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'StoryBoard-Data'

instancevar . .

users
    ^users ifNil: [ users := OrderedCollection with: (SBAdministrator new
        userid: 'admin';
        password: 'admin';
        yourself)
    ]

resetUsers
    " SBUser resetUsers "
    users := nil

Iteration>on: aProject
    ^self new
        project: aProject;
        yourself

(mock)

+2

All Articles