Problem/Motivation
The current migration workflow is roughly: we presume where certain things from D6/D7 ended up in D8. Then we write a migration which codifies this presumption and then check whether the raw values are in place. But that's basically testing the migration pipeline / CRUD APIs instead of testing the presumptions.
Proposed resolution
Where possible and economical check actual functionality depending on the values migrated. See the interdiff attached: the first test was testing whether the parent link ID was a certain string. This is almost meaningless as that's the string we write there, the semantic meaning is not tested. The second test ensures whether a menu tree contains them as we want.
Remaining tasks
Identify which migrations can be tested better (config objects and entities are ripe for this) and then do it.
Basically, wherever you find an API, use it. For example comment.status was behaving stupid in earlier Drupals , it was 0 for published and we got this right (see "status: status #In D6, published=0. We reverse the value in prepareRow.") but -- if we would've forgotten this detail then merely asserting $comment->get('status')->value
to 0 would not lead to anywhere. Checking $comment->isPublished()
does go somewhere. Of course, status is not tested at all in MigrateCommentTest but at least we didn't get it wrong :)
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
interdiff.txt | 3.77 KB | chx |
Comments
Comment #2
chx CreditAttribution: chx commentedComment #3
phenaproxima+∞ for this!!
Migration tests should be ruthless. They should assert everything they can. The fact that the migration system does not validate the migrated data makes this even more crucial.
My feeling is that, if you are testing a migration that you expect to migrate 10 nodes and skip one, then you should assert all of those 10, and every migrated property thereof -- and you should assert that the 11th did not get migrated. The migration tests have greatly improved recently (much more readable and writeable), so there's no particular reason to avoid ruthless testing.
I completely agree that migrated values should be tested using accessor methods rather than raw values. We should always use
isPublished()
overget('status')
.We should also be aware of values which are likely to change frequently in our fixtures (aggregator feed eTags, for example) and make our assertions smarter. In certain cases, it makes more sense to assert a format (like "assert that this is a hex string 32 characters long") than a static value.
Not entirely sure how to proceed, but maybe we can start by writing up a laundry list of complaints/shortcomings in the existing migration tests.
Comment #4
quietone CreditAttribution: quietone commentedDefinitely agree. I know I need to learn this and any guidance would help.
And just today ultimike asked if tests are needed for a very simple change, https://www.drupal.org/node/2598376#comment-10479044.
A laundry list of shortcomings, or if someone prefers, 'the ideal' is a good place to start.
Comment #5
chx CreditAttribution: chx commentedI posted how to test that issue and more importantly, how to figure that one
Comment #6
catchComment #7
benjy CreditAttribution: benjy at PreviousNext commentedWhy improving some test coverage a migrate critical? I agree this is a good issue, someone just needs to go through every test and manually analyse the assertions.
Comment #8
chx CreditAttribution: chx commentedBecause we can't ship if we have blunders like menu parents not migrating at all and I am a complete loss at how to catch all those bugs if not with meaningful tests.
Comment #9
quietone CreditAttribution: quietone commentedFor reference, #2598376: d6_user_settings migration user_register constants don't seem to line up. has an example of testing by building the relevant admin form and checking the values there.
I generally think in lists and phenaproxima mentioned laundry list above so I'm empowered to write up a summary list.
Migration tests
Are 'use accessor methods' and 'check actual functionality' the same? What's missing?
Comment #10
chx CreditAttribution: chx commentedThe scale goes like this: direct property access, totally useless. Accessor method, is only almost useless. :) because at least it checks we didn't make a tpyo ;) in the name of the key but the correctness of the value can not be checked that ways.
No, what you need is functionality, one way or another. That admin form was a great example.
Comment #11
quietone CreditAttribution: quietone commentedThx, chx. Moved the types of tests into a new list. And changed ruthless to rigorous.
Migration tests
Preferred order of testing methods
And something like if you aren't using method 1, make a comment in the code?
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #14
mikeryanWe removed the migrate-critical tag - this issue as it is is too vague to be actionable. Let's make it a meta and add concrete child tasks to beef up the testing.
Comment #16
heddnThere are no concrete child tasks added yet. There has been active work outside of this issue in improving the test coverage of migrate. Does this issue still serve a purpose? Tagging for an IS update.
Comment #17
heddnMoving to NW, not because there is a patch, but because as a plan/meta issue, there is a lot of work needed on this issue.
Comment #20
phenaproximaI think we can close this one.
Back when this issue was opened, the Migrate test suite was a lot shoddier than it is today. After a lot of aggressive refactoring and improvement, Migrate's tests are significantly more hardened than they used to be.