Testing best practices opinion needed on testing assets

classic Classic list List threaded Threaded
21 messages Options
Reply | Threaded
Open this post in threaded view

Re: Testing best practices opinion needed on testing assets

Ralph Schindler-2

> To sum up: I think you (we) should start moving all mock implementations
> into the core of the component, and make them part of it. Any other
> asset to the tests is just a fixture like any other piece of data.

Interesting points.  I would say the Mock implementations should stay in
the tests/ folder as they are not part of the use-case API.  That said,
I think it's EXTREMELY important that when designing a component that
any external dependencies in the form of a proxy-ing object should be
injectable, and at worse case, lazy-loaded when needed.  This means that
the mocks that exist can be injected during test-time.

The reason I'd say they don't belong in the library/ folder is due to
the nature of PHP.  Being in the library, that means that objects that
are purely there for testing are available to an application since the
library is in the include_path.  In addition to it being accessible via
the application (which I argue against), it might cause confusion as per
the role of certain objects/classes in the context of writing an
application. (This is why I argue that tests/ belong outside of a
package/component/whatever you call it).

To sum it up:
Things that are for testing go in tests/.
Things in the core library/ should always allow for dependency injection.