Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 7 years ago

Last modified 6 years ago

#3567 closed enhancement (duplicate)

Unit Testing for BuddyPress!

Reported by: foxly Owned by:
Milestone: BuddyPress.org Sites Priority: normal
Severity: major Version: 1.5
Component: Core Keywords: needs-patch
Cc: chrisclayton, fanquake@…

Description

The BP-Media team has added automated unit testing to BuddyPress 1.5.

This is a fully working app, to run it:

1) Create a database called "bpm_test"
2) Create a user on "bpm_test" called "test" with password "test"
3) In a terminal window, navigate to /buddypress/unit-test/ , type "php test.php", and hit enter

The automata will run the sample unit test we've built for you, along with any other unit tests you create.

We'll be happy to walk you through how all the code works in chat next week.

Change History (17)

#1 @foxly
9 years ago

256kb upload limit on trac. Right then. Posted on our Google Code site.

Here's the link:

http://code.google.com/p/buddypress-media/downloads/detail?name=buddypress-unittest.zip

#2 @nacin
9 years ago

This is nifty -- I'd be great to see this integrated into the existing WordPress unit testing framework. There, it's possible to drop in your own config, plugins, and tests.

#3 @foxly
9 years ago

It's already based on the WP unit test runner, so compatibility should be relatively easy.

Our changes add the following capabilities on top of WP's solution:

1) Installs, loads, and tests *plugins* inside a WP install
2) Works from any folder on the system with no mods
3) Doesn't require the user to install PHPUnit, so end-users can run the tests on their servers to help plugin authors remotely debug their code
4) Runs under Windows, Linux, and OSX with no configuration changes

Overall it just makes it *way* easier for plugin authors to do unit testing.

#4 @boonebgorges
9 years ago

I've only just glanced at it, but it looks really sweet. Using PHPUnit Portable is a very thoughtful enhancement to the WP automated tests, and will lower the bar for developers to start writing tests for their code (I recently wrote about what a pain it can be to get PHPUnit running standalone in some environments http://teleogistic.net/2011/08/setting-up-phpunit-with-mamp/)

I guess I would personally prefer to have the unit tests broken out (so that you don't have to download the entire BP package along with it) so that I could use them with my own Git/svn checkouts of BP. It's easy enough to copy the unit-tests folder into my dev environment, but that would be kind of a pain if I wanted to dev against BP and the tests at the same time. Ultimately, it would be nice to move to a system where the BP dev package would include the app itself in a subdirectory, with the unit tests in another subdirectory, so that they're automatically available to all developers. This is how it works with lots of software packages, and I think it's really a prerequisite to doing test-driven development. Anyway, that's for some point in the future, when and if the tests have decent enough coverage to warrant it.

Now to start writing tests - I see that there are only three so far :) We should have a discussion about getting the tests into shared space where the core devs can contribute to test coverage alongside your team, and anyone else who wants to submit patches. What are your thoughts about this, foxly?

Last edited 9 years ago by boonebgorges (previous) (diff)

#5 @foxly
9 years ago

1 - Yes, that's why we forked PHPUnit and created PHPUnit Portable... :)

2 - The exact implementation of the test runner is a bunch of trade-offs. We set it up the way we did so that it could be checked-in to a version control system. That way, when other developers check-out our code, they have a fully functional pre-configured unit test environment that's up and running in a matter of seconds.

It would be quite easy to modify it to work with multiple plugins at once, or have a master install in the BuddyPress plugin and then have it load unit tests from the individual plugin directories ...but we should probably let it mature a bit first.

3 - Actually, there's only one unit test in there, the other functions are set-up and tear-down code. In our experience its best to have only one unit test per file so you can just disable a given file when you want to run a test. Take a look at our SVN to see how we've implemented things.

4 - I think shared unit tests are an excellent idea, especially now that BP 1.5 is really starting to interact with other plugins. We'd be happy to include your unit tests in our automata to make sure BP-Media isn't introducing defects via hooks, filters, or other vectors.

5 - I just want to clarify that we're not volunteering to be the "BuddyPress Unit Test Team" here. We've built you the technology, but you guys are the ones that have to go out and use it :)

#6 @boonebgorges
9 years ago

We've built you the technology, but you guys are the ones that have to go out and use it :)

That's really what I wanted to hear :) I think that we should move something like this into core development, and I wanted to make sure that you were offering up your foundation for potential integration into the distributed BP package. You've done much of the hard work!

#7 @foxly
9 years ago

Yes, by all means take our code and put it in your core! ...that's how open-source works, right ... :)

You can also probably save many, many hours of dev time by using BP-Media's unit tests as design patterns for your own test code. We've already done a ton of the heavy-lifting, building code that spins test arrays and database results into structures that PHPUnit's "assertX" functions work with.

You can grab them at this link: http://code.google.com/p/buddypress-media/source/browse/#svn%2Fbp_media%2Ftrunk%2Funit-test%2Fbpm-testcase

Also, be sure to heavily document your unit tests. Remember, you're effectively creating *working examples* demonstrating the use of *every* function in BuddyPress. If you document them well, you can literally "cut-and-paste" them into your codex as documentation!

Here's an example from the (partially completed) BP-Media codex:

http://code.google.com/p/buddypress-media/wiki/DOCS_BPM_db_select_runSelectQuery

We'd like to get together with you in Google+ video chat sometime next week to run you through using the Unit Test framework. It should take less than an hour. Perhaps after Wednesday's dev meeting would be most convenient?

#8 @boonebgorges
9 years ago

  • Milestone changed from Awaiting Review to 1.6

I'd be happy to have a chat. After the Wednesday meeting should work for me.

#9 @DJPaul
9 years ago

  • Milestone changed from 1.6 to Future Release

#10 @fanquake
9 years ago

Hey guys,

Just wondering if you've been working with our Unit Tests, or written any tests yet?

Last edited 9 years ago by fanquake (previous) (diff)

#11 @chrisclayton
8 years ago

  • Cc chrisclayton added

#12 @fanquake
8 years ago

  • Cc fanquake@… added

#13 @chrisclayton
8 years ago

  • Keywords needs-patch added; has-patch removed

The download is no longer accessible. Since it wasn't uploaded as an attachment, I'm removing the 'has_patch' tag.

#14 @fanquake
8 years ago

This ticket should really be closed in favour of #4442

#15 @boonebgorges
7 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Closing in favor of #4889.

#16 @sooskriszta
6 years ago

  • Milestone changed from Future Release to Unit Tests

#17 @johnjamesjacoby
6 years ago

  • Milestone changed from Unit Tests to BuddyPress.org
Note: See TracTickets for help on using tickets.