I have started using BDD for a WordPress plugin i'm working on and i'm rewriting the js codebase to do tests. I've encountered a few problems but i'm going steady now, i was wondering if i had the right approach, because i'm writing test that should pass in a normal browser environment and not inside WordPress.
I choose to do this because i want my plugin to be totally independent from the WordPress environment, i'm using requirejs in a way that i don't expose any globals and i'm loading my version of jQuery that doesn't override the one that ships with WordPress. In this way my plugin would work the same on every WordPress version and my code would not break if they change the jQuery version or someone use my plugin on an old WordPress version. I wonder if this is the right approach or if i should always test inside the environment i'm working in. Since WordPress implies some globals i had to write some function purely for testing purpose, like

"get_ajax_url": function() {
    if( typeof window.ajaxurl === "undefined" ) {
        return "http://localhost/wordpress/wp-admin/admin-ajax.php";
    } else {
        return window.ajaxurl;

but apart from that i got everything working right. What do you think?


I think you're on the right track, including your methodology.

As an enhancement, you could create additional tests that run within the wordpress application environment. You might want to do this if you needed to generate additional diagnostic information when a failure occurs. Another situation is if you needed advanced triggers to be fired that can only occur within the application / plugin and aren't triggered by user interaction.

At a more abstract level, what you're doing is creating test sets based upon how the user will interact with your application / plugin. For the beginning and intermediate stages of test design, this is an excellent place to start. It presents the most value / reward for your effort and it gives you a degree of assurance that your users will get what you expected.

Guaranteeing the UI experience will go a long way towards keeping your user base happy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.