Love the idea, great explanation! I see value in this going forward.
Definitely interested.

From:   "Chen, Shaoquan" <>
To:     "OpenStack Development Mailing List (not for usage questions)"
Date:   07/19/2015 05:34 PM
Subject:        [openstack-dev] [Openstack][Horizon] Sharable Angular mock

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
  *   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 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:


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.


OpenStack Development Mailing List (not for usage questions)

OpenStack Development Mailing List (not for usage questions)

Reply via email to