How to mock NSURLConnection.sendAsynchronousRequest in unit testing?

Do you use unit testing in wordpress development?

  • I have been asked whether our web development team uses unit testing to develop themes and plugins for wordpress.org. Do you use unit-testing in WordPress development? If so, why, what tools do you use? and what benefits does it confer? Do you think it is necessary?

  • Answer:

    I think its silly and not in the best interest of the client to not have a basic document on hand to run through when you make changes such as plugins and php customization to your site.  On that note, we had this discussion at a meetup this month and a fellow developer suggested a tool called Shippable.    It does unit testing and auto deploy.  The auto deploy scares me a bit, personally.    I havent tried this service, but the developer had great things to say about this.

Mauri Rummel at Quora Visit the source

Was this solution helpful to you?

Other answers

Yes, by maximizing the code that doesn't depend on the Wordpress framework or libraries. This makes it much easier to run tests on plain PHP code that doesn't even load Wordpress.

J. B. Rainsberger

I do use unit testing for our WordPress plugin: https://github.com/LaunchKey/launchkey-wordpress. It currently uses a facade for interacting with all of the globals in WordPress to make it testable with https://github.com/mlively/Phake for object mocking. After speaking with at the most recent ZendCon, I am investigating switching to https://github.com/10up/wp_mock with https://github.com/padraic/mockery for object mocking. It's probably not the best example of unit testing WordPress you will find as this is my first time unit testing WordPress. As time goes by, the readability and quality of the tests will improve. Unit testing has its own merits especially with our project being open source. But, if I were delivering code to a client or not, I would still unit test code that I was not going to throw away. All code requires enhancements, bug fixes, and eventually refactoring. In order to perform those actions with confidence, unit tests are required. Another thing I plan to add to the tests is real world browser testing of the deployed plugin. I just haven't found a good methodology that will work within our security concerns.

Adam Englander

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.