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

CommentFileSizeAuthor
interdiff.txt3.77 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx created an issue. See original summary.

chx’s picture

Issue summary: View changes
phenaproxima’s picture

+∞ 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() over get('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.

quietone’s picture

Definitely 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.

chx’s picture

I posted how to test that issue and more importantly, how to figure that one

catch’s picture

Priority: Normal » Major
Issue tags: +Migrate critical
benjy’s picture

Why 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.

chx’s picture

Because 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.

quietone’s picture

For 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

  • Will be ruthless.
  • Assert every possible value, i.e. all fields on a node, all source values.
  • Assert that items skipped are, in fact, skipped.
  • Use accessor methods.
  • Check actual functionality.
  • Handle values that change frequently in any fixture, i.e. aggregator, feed, tags.
  • Follow PHPUnit style as appropriate, i.e. assertIdentical($expected, $actual).
  • Have documentation with examples.

Are 'use accessor methods' and 'check actual functionality' the same? What's missing?

chx’s picture

The 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.

quietone’s picture

Thx, chx. Moved the types of tests into a new list. And changed ruthless to rigorous.

Migration tests

  • Will be rigorous.
  • Assert every possible value, i.e. all fields on a node, all source values.
  • Assert that items skipped are, in fact, skipped.
  • Handle values that change frequently in any fixture, i.e. aggregator, feed, tags.
  • Follow PHPUnit style as appropriate, i.e. assertIdentical($expected, $actual).
  • Have documentation with examples.


Preferred order of testing methods

  1. Functional testing.
  2. Accessor method.
  3. Direct property access.

And something like if you aren't using method 1, make a comment in the code?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

Issue tags: -Migrate critical
mikeryan’s picture

Title: Ensure migration tests are meaningful » [meta] Ensure migration tests are meaningful

We 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

There 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.

heddn’s picture

Status: Active » Needs work

Moving 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

phenaproxima’s picture

Status: Needs work » Closed (outdated)

I 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.