WordPress plugin testing unit test or acceptance test or both

I’m building a WordPress plugin and I want to build using test driven development.

The first thing I want to test / build is a login form.

Read More

I’m unsure if I should be unit testing it, acceptance testing or both.

I’ll be using PHPUnit and Selenium.

The first thing I started looking at is displaying the login form. Is it good practice to unit test returning HTML?

Also this form may contain error messages on failed logins. Would this be a different unit test or is this best left to acceptance testing?

I’ll post some code example if I need to clear anything up.

Thanks

Related posts

Leave a Reply

1 comment

  1. (Ian pinged me on Twitter and asked me to provide some feedback)

    First, I will say that I have not used the combo of PHPUnit and Selenium for doing acceptance testing. I use Behat + Mink to do that, but that’s not the issue here I think.

    To test a login form, you could do unit tests AND acceptance tests. It’s just a question of whether or not you feel it’s valuable to do both. I think from the perspective of building a WordPress plugin, you will get a much better return on the time creating the tests to go with acceptance tests.

    Some other answers:

    1. Unit testing stuff that spits out HTML is totally acceptable. After all, the goal is to make sure that individual module of code works correctl
    2. Testing that error messages on failed logins occur should be in it a separate test. These days, I like to practice “one assertion per test” at the unit level

    Hope this helps!