-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is a Unit Test? #96
Comments
WP_Mock exists specifically to empower developers to write unit tests for
their plugins and themes without having a dependency on WordPress core to
run the tests.
I think you've fundamentally misunderstood this library if you think it's
for integration testing.
…On Fri, May 26, 2017, 1:12 AM Josh Habdas ***@***.***> wrote:
WP_Mock is an API mocking framework, built and maintained by 10up for the
purpose of making it possible to properly unit test within WordPress.
Sorry to bother you. But I've been doing some research while building out
unit tests for a WordPress plugin I'm building and discovered a misnomer in
the vernacular being used in the community with regard to what actually
constitutes unit testing.
My understand is that, in using WP_Mock or similar, while creating
WordPress plugins what was is doing is actually creating an "integration
test" and not a "unit test".
To help justify my rationale I've set-up an application capable of both
unit tests and integration testing. Here's what an example *integration
test* looks like:
/** * Sample test case. */class SampleTest extends WP_UnitTestCase { /** * A single example test. */ function test_sample() { // Replace this with some actual testing code. $this->assertTrue( true ); }}
It's an *integration* test because it *requires* an understanding of and
dependence on WordPress internals in order to execute.
Whereas here's what an actual *unit test* looks like:
namespace hyperdrive\spec;use function hyperdrive\enter_hyperspace;describe('hyperdrive', function () { describe('enter_hyperspace()', function () { it('echos empty script given empty string', function () { $closure = function () { enter_hyperspace(''); }; expect($closure)->toEcho('<script></script>'); }); it('echos string in script given string', function () { $closure = function () { enter_hyperspace('Danger, Will Robinson!'); }; expect($closure)->toEcho('<script>Danger, Will Robinson!</script>'); }); it('does not echo unexpected string', function () { $closure = function () { enter_hyperspace('Danger, Will Robinson!'); }; expect($closure)->not->toEcho('<script>Warning! Warning!</script>'); }); });
Above snippet copied from hyperdrive.spec.php
<https://github.com/comfusion/hyperdrive/blob/master/spec/hyperdrive.spec.php#L25-L46>
and licensed for reuse under AGPL.
Notice there is *no reliance* on WordPress in order to operate; code is
operating on PHP source capable of being run in any system and independent
WordPress internals.
Which begs the question, what is actually considered a unit test when
working with WordPress, and should the community consider adjusting
vernacular to help prevent misunderstanding and starting with adjusting the
blockquote pulled from the WP_Mock README file copied above?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#96>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAbRcQ8sxNDCppLpBcECmPD-jjhSVISXks5r9m1QgaJpZM4NnNki>
.
|
Ah! I see where my logic failed me now. I saw the class-based approach and thought |
ghost
closed this as completed
May 26, 2017
This issue was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry to bother you. But I've been doing some research while building out unit tests for a WordPress plugin I'm building and discovered a misnomer in the vernacular being used in the community with regard to what actually constitutes
.My understand is that, in using
WP_Mock
or similar, while creating WordPress plugins what was is doing is actually creating an "integration test" and not a "unit test".To help justify my rationale I've set-up an application capable of both unit tests and integration testing. Here's what an example integration test looks like:
It's an integration test because it requires an understanding of and dependence on WordPress internals in order to execute.
Whereas here's what an actual unit test looks like:
Above snippet copied from
hyperdrive.spec.php
and licensed for reuse under AGPL.Notice there is no reliance on WordPress in order to operate; code is operating on PHP source capable of being run in any system and independent WordPress internals.
Which begs the question, what is actually considered a unit test when working with WordPress, and should the community consider adjusting vernacular to help prevent misunderstanding and starting with adjusting the blockquote pulled from the
WP_Mock
README file copied above?The text was updated successfully, but these errors were encountered: