-
Notifications
You must be signed in to change notification settings - Fork 0
Testing_DMA
From The Cucumber Book, page 237:
’When Do I Use the UI and When Do I Use Models Directly to Create Records?
A Given means that something has happened in the past. If a Given describes stuff that should be in the database, it is usually preferable to create those records directly using the database (ActiveRecord)—without going through the UI. This gives us the freedom to implement certain functionality without depending on other UI screens to be developed first. It also runs faster and makes our step definitions simpler. The RSpec Book [CADH09] calls this pattern DMA—Direct Model Access.’
Done properly, DMA can allow our test suite to be more readable, and faster at the same time. As an example, switching our login scenarios to use the UI only for test that actually test login functionality netted roughly a minute shorter test runs. There are many things that can slow down a test suite, and this is one of them
In short, try to keep tests (whether specs of features) focused directly on what you are trying to test. If there is setup needed, make sure that setup is tested somewhere (and add it if not), then build out the data as needed in a reusable place - making sure to use the absolute minimum amount of data required to effectively test your target. Every little unneeded thing added to the test suite slows it down, until one day you run the tests, and they are much slower than they were just a short time ago. This is something that needs ongoing vigilance and refactoring of tests as needed. Never be afraid to refactor tests, they need it just as much as your code does!