[openstack-dev] [Openstack][Horizon] Sharable Angular mock

Chen, Shaoquan sean.chen2 at hp.com
Mon Jul 20 00:21:07 UTC 2015

Currently random mock objects are created inside of spec files to make writing unit tests easier. This approach works but has some drawback:

  *   mocks are not sharable between specs.
  *   mocks are usually too simple.
  *   mocks may not be consistent between spec files.
  *   mocks are not tested theme self.
  *   hard to maintain and manage.

In order to make it easy for developers to write high quality unit tests and e2e test, we want a set of high-quality mock objects. To make its easy to maintain:

  *   mocks should reside in ``.mock.js`` files and be loaded only in test runner page
  *   mocks should be loaded after production code files, before spec code files.
  *   mocks should be sharable between specs.
  *   mocks are not belong to specs, they should have a 1:1 relationship with the object it try to mock.
  *   mocks should be at a level as low as possible, maybe where JavaScript cannot reach directly.
  *   mocks must be tested theme self.
  *   mocks should be easy to find, use and manage.

I drafted a simple BP at https://blueprints.launchpad.net/horizon/+spec/horizon-angular-mocks to summaries the issue existing in Horizon IMO and how I could see to fix them. I also setup two patches to prove the concept at:

  *   https://review.openstack.org/#/c/202817/
  *   https://review.openstack.org/#/c/202830/

This mock is for the window object and another could be OpenStackHtttpBackend which mimic all the behaviors of Horizon Web services. As you can see, the window mock object can be easily applied to a bug Tyr fixed recently so that the spec code do not need to create an inline mock object. Because those shared mock are independent from specs, they can be more neutral and can have much more features than a over simplified mock for a specific test.

Please let me know if this interested you.


More information about the OpenStack-dev mailing list