googleinterns / smart-home-testing

Apache License 2.0
1 stars 2 forks source link

Integration Testing for Smart Home Actions

Testing Library for Smart Home

The problem

Smart home developers currently use a manual tool for testing. To solve friction in the development process, the goal is to create a way for developer's to receive more detailed information on why their errors occur.

This solution

The Smart Home Integration Testing Library introduces this solution for developers. With the enhanced logging, developers will be able to find more details about failures. The big impact of this will be removing friction and latency from the dev cycle, which will allow the developer to successfully verify their action more efficiently.

This repository consists of:

Installation

Use the package manager npm to install the packages used for the testing library

git clone https://github.com/googleinterns/smart-home-testing.git
cd smart-home-testing
npm install

Initialize the smart home schemas, included in the project as a submodule:

git submodule init
git submodule update

Examples

As previously stated, the tests folder contains examples on how the library would interact with a developer's tests for each intent. This section will break down a simple validation test further. In this example, we will be focusing on a SYNC test using the Jest framework.

Import the testing library modules in your tests

//__tests__/example.test.ts
import { testlib, testreqs } from 'smart-home-testing'

If using your own fulfillment, make sure to import your app as well

//__tests__/example.test.ts
import * as your-app-here from '../your-app-here'

Use the library functions to generate a SYNC request to pass in as a parameter to your SYNC intent handler

//__tests__/example.test.ts
describe.only('Sync response testing suite', () => {
  const requestSync = testreq.generateSyncRequest();
  const responseSync = fakeapp.onSync(requestSync);
  ...
  });
});

Call the validation function in the test.

//__tests__/example.test.ts
describe.only('Sync response testing suite', () => {
  // Generating SYNC Requests and Responses
  const requestSync = testreq.generateSyncRequest();
  const responseSync = fakeapp.onSync(requestSync);

  // Validating the SYNC response
  test('Sync Response using actions an intent handler', async () =>{
    // This will indicate to the validation function that SYNC is being called and
    // will validate the SYNC intent against the current SYNC JSON Schema.
    const testlibValid = testlib.validate(requestSync, responseSync);

    //If the response shows no errors, `testlibValid` will return undefined.
    //If there are errors, the function will return an array of errors.
    expect(testlibValid).toBe(undefined);
    //In this case, testlibValid returns undefined, so the test passes.
    });
  });
});

Issues

🕷 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior on GitHub.

❓ Questions

Please visit StackOverflow, Assistant Developer Community on Reddit or Support

🤔 Other references

Contributing

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Disclaimer

This is not an officially supported Google product.