Error when running Unit Tests

Error when running Unit Tests

by Gerard Ramos -
Number of replies: 5
Hi all,

I've been getting some issues when running unit tests (admin -> reports -> unit tests -> Run Tests). I get the error:

Fatal error: Call to undefined method AutoGroupTest::GroupTest() in D:\xampp\htdocs\moodle\admin\report\unittest\ex_simple_test.php on line 31

I tried this with the "Only run tests" field blank and with "question" entered (so running unit tests for question only). Same error occurs.

I had a look in moodle/lib/simpletestlib/test_case.php (the file that's included in the file above), and the class GroupTest() is deprecated and contains no functions.

I re-installed moodle, the issue still arises. This is on a local server (hence the xampp), but similar errors pop-up on the server i have it running on too.

My moodle version is 1.9.5+. On the server it's running linuz+apache(php 5.3)+mysql, at home i'm running windows+xampp (apache(php 5.3)+mysql))

I'm not sure if this is a bug (I think it might be a pathing issue on my side), and I haven't used the tracker before, so I decided to come here first. Any help would be greatly appreciated.

Thanks
Average of ratings: -
In reply to Gerard Ramos

Re: Error when running Unit Tests

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well I just tried, and they all worked for me. This is in my 1.9.5+ checkout. I ran all the tests and got

23/23 test cases complete: 635 passes, 0 fails and 0 exceptions.
In reply to Tim Hunt

Re: Error when running Unit Tests

by Gerard Ramos -
Cheers for the feedback Tim. It's a fresh 1.9.5+ install for me, but since yours is working it must be something on my end. On the linux web (server accessed remotely) i have going the error is slightly different:

Fatal error: Cannot redeclare class courselib_test in (path to www folders)/moodle/course/simpletest/testcourselib.php on line 83

That's from a fresh install also. Can anyone else replicate this problem?

I tried replacing the unittest and simpletestlib folders with the latest 1.9.5+ CVS folders and I still get the same error.

Edit: Mind you the fresh install i did on my home computer was from the downloaded zip file from the downloads page. I'll try deleting and checking out the whole thing via CVS tonight.
In reply to Gerard Ramos

Re: Error when running Unit Tests

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Could it be an include path problem that is causing require_once to get confused and include the same file more than once?
In reply to Tim Hunt

Re: Error when running Unit Tests

by Gerard Ramos -
Ah found the problem!

I commented out this line of code:

$this->GroupTest($test_name);

And it works now! I found in the constructor of the AutoGroupClass class in /unittest/ex_simple_test.php, and it turns out the GroupTest class in /lib/simpletestlib/test_case/php is deprecated and was left blank similar to this:

/**
* @deprecated
*/
class GroupTest extends TestSuite { }

I think the reason the page was complaining was PHP version related. On my server and on my local setup i was using PHP 5.3.0. I tried it on another setup (without the first line commented out) with PHP 5.2.* and it worked.
In reply to Gerard Ramos

Re: Error when running Unit Tests

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes. Must be PHP 5.3 related. Obviously it should work there. If you can be bothered, please file a bug at http://tracker.moodle.org/ saying 'Unit tests do not work with PHP 5.3'.