Salesforce Developers put out the blog post [Testing Custom Metadata Types][1] that includes the section *Testing Global Custom Metadata*.

> ...add an extra field to your custom metadata type to indicate what sort of tests the type is active for. For example, you could add a Text field called TestCase__c to your type. You can leave this field blank for production custom metadata and set it for test custom metadata.

[![enter image description here][2]][2]

Class with static setting to toggle records to retrieve.

    public class TestContext {
        public static String testCase {public get; public set;}
    }

Queries against the custom metadata type use the static setting to retrieve testing configuration.

    OurCustomMetadata__mdt[] rows =
        [SELECT QualifiedApiName, Field1__c
         FROM OurCustomMetadata__mdt
         WHERE TestCase__c = :TestContext.testCase];

Test indicates which configuration to use.

    public static testmethod void testWelcomePageWorksWithTestCase1() {
        TestContext.testCase = 'TestCase1';
        /* test the Welcome page */
    }

Personally I find the proposed solution a bit ugly and have voted for [Custom MetaData Types need APEX methods to access/update][3].

See also:

 * [Insert Custom Metadata for Unit Test][4]


  [1]: https://developer.salesforce.com/blogs/engineering/2015/05/testing-custom-metadata-types.html
  [2]: https://i.sstatic.net/Fj4AC.png
  [3]: https://success.salesforce.com/ideaView?id=0873A000000lD5pQAE
  [4]: https://salesforce.stackexchange.com/q/111375/102