1

Has anyone done unit testing with their Joomla extensions? Can you share how to do this? I was wondering if it's good to do unit testing for extensions or if it's an overkill and should only be done for complex components?

user1448031
  • 2,172
  • 11
  • 44
  • 89

2 Answers2

1

It's pretty much impossible for the majority of extensions to unit test with PHPUnit etc. because the core classes are so coupled to each other. If you're going to write tests the best way is to use something like Selenium to do in browser tests!

George Wilson
  • 5,595
  • 5
  • 29
  • 42
  • I thought Selenium has to be used with PHPUnit for automating unit tests. So what you are suggesting is I can use Selenium to do unit testing instead of using PHPUnit? I found some articles about Selenium in Joomla docs but the articles seem like they were written for testing Joomla core. – user1448031 Apr 13 '14 at 06:29
  • Well selenium works in tandem with PHPUnit - but you can use PHPUnit directly for testing classes. You can use exactly the same principles for testing Joomla Core as any other extension. I understand SH404 uses selenium for testing their extension so it's definitely doable! – George Wilson Apr 13 '14 at 17:52
1

I disagree with @GeorgeWilson.

If you code properly, your models should mostly be independent, much the same for your helpers.

Regarding controllers, usually there is no need to test them, but in case you want to, simply instantiate mock ups of models that only expose the interfaces and return the expected results.

There are very few examples, a neat one is in simplecustomrouter, it doesn't expose the instantiation of different models as it's a simple plugin, but it will give you a head start.

Riccardo Zorn
  • 5,590
  • 1
  • 20
  • 36