Developers' test suite

Developers' test suite

by Matt Oquist -
Number of replies: 18
Recently finding myself with CVS access, I realize that I need to do better testing than I've been doing for the little project I've been working on in /contrib, which has ample warnings that it's NOT PRODUCTION READY, etc.

Surely I'm not the first person who will be developing tests for Moodle. smile

Is there a test suite for developers that I can obtain somewhere?

If not, does anyone have comments to make about the best way to start creating a common test suite? I've never done QA engineering before (so be warned), but here are a few thoughts to get things started:
  • develop the test suite under /contrib/developers_tests
  • develop a parent class ("devtest"?) under which individual [sets of] tests are then loaded as sub-classes
  • individual [sets of] test sub-classes should be located in /contrib/developers_tests/tests (or something like that)
  • going to http://your-dev-moodle.com/devtest (or something like that) should bring up a page from which you can select tests to run
  • we should probably have some sort of "grading" or "grouping" mechanism so that tests can be selected as predetermined groups, e.g.:
    • Base Tests
    • User Interface Tests (should include descriptions of intended appearance of UI elements)
    • Database Tests
    • Library API Tests
  • each test should identify the minimum and maximum Moodle versions it's known to test correctly
I'm sure lots of people have already developed their own tests and testing procedures, so hopefully the above is all moot. Where is all this shared, or where could we share it?
Average of ratings: -
In reply to Matt Oquist

Re: Developers' test suite

by Petar Atanasov -
In addition to your suggestion - the test module should include:
For both functionality and db:
- regression tests (test of new functionalities and check if the're backward compatible to older versions of moodle)
For the db:
- database integrity tests  (checking integrity of data), in  order to create such test a database description must be created (I haven't found any 'till present)

Recently I started creating database object model of the the current mysql version, but this seems a liitle bit more to reversing the database sad

I've also searched for moodle QA (as well as performance tests), but did not found anything.
Althoigh you state that "..I've never done QA engineering before..." that's the precise mechanism which you describe for creating automation test and performing QA.
I'm ready to share the database model description (when I finish it big grin ) and join you in the proscess of creation test module.

Regards
Petar

In reply to Petar Atanasov

Re: Developers' test suite

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Matt,

You may find the Tests documentation of interest. (Thanks to Christian. approve)
In reply to Helen Foster

Re: Developers' test suite

by Matt Oquist -
Indeed! Thanks for the URL.
In reply to Matt Oquist

Re: Developers' test suite

by David Scotson -

The Open University has been writing unit tests for some of the stuff they've been working on. Some of it is for internal integration but they have said they'd make their other tests available once they've met internal deadlines and got some spare time.

It's certainly a good idea for all Moodle developers to be contributing to a single unit test bank using the same testing tools. Hopefully leading to more happy moments like this one.

There's a thread here which starts off talking about automating the type of User Interface test that Helen linked to in the Docs, but then diverges onto discussions about unit testing and the type of tools people are currently using.

I actually think that testing with a tool like Selenium is crucial as a complementary approach. It's all gone a bit quiet on that front though I did see someone talking about using it to test backup.

In reply to David Scotson

Re: Developers' test suite

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Christian, who was working on it, is no longer working with us and we're overwhlemed with some other projects at the moment, hence the hiatus. But I do want to see it become mainstream.
In reply to Matt Oquist

Re: Developers' test suite

by Martín Langhoff -
I talked with Rod Norfor @ OU about their test suite -- I don't remember what it is based on, but it is a unit-test type of framework, great for testing datalib, moodlelib, etc.

And Christian Lebe was drafting a Selenium-based approach to tackle web UI testing, and now I see MartinD mentions that's dormant for the time being. There was also talk about 'seed' databases with sample data for these test banks.

I do think we need two testing frameworks: both things are mighty important. For the work I do, the unit testing stuff would be great.
In reply to Martín Langhoff

Re: Developers' test suite

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I last posted about this here: http://moodle.org/mod/forum/discuss.php?d=43569&parent=200593

Now, wearing my quiz module maintainer hat, I want to get this checked in to HEAD next week.

In my previous post, I identified some issues/naming conventions that we needed to sort out:
  • The testcases themselves we have put in folders called 'simpletest', with filenames like text_xxx.php, so you have a /lib/simpletest/testdatalib.php
I think this is fine and we should stick with this.
  • Then there are the simpletest libraries, which we will have to move into a subfolder of lib.
I think this is fine. I'll check them in.
  • Then there is the testing infrastructure, which basically crawls the directory tree (or a subset of it) looking for all the files called **/simpletest/test*.php, and runs the tests they contain (with various options) and displays the results prettily. At the moment we put this in a '_tools/runsimpletest' top level folder, but we may want to rethink that.
I think the place I this code should live is in an 'admin/unittest' folder, and I should make sure the tests can only runnable by admins (they can put quite a heavy load on the server).

If you want to object to any of this, let me know before Monday. What is the best way to ping Martin D to make sure he sees this?
In reply to Tim Hunt

Re: Developers' test suite

by Matt Oquist -
Are these tests intended ever to be run by regular admins, or only ever by developers?

If they're only intended for developers, I don't think it makes sense to have them in HEAD, because it's just extra stuff sitting around taking up space and bandwidth and waiting to be exploited.
In reply to Tim Hunt

Re: Developers' test suite

by Matt Oquist -
Since I started thinking about this problem just a few hours ago, I had already considered and rejected the option of having a test infrastructure that crawls a directory structure. But I guess I don't have any strong objections to it.

I do think we really need some way of grouping tests and perhaps indicating some level of granularity. Some tests are high-level and some are super-anal, and the rest are in-between. I don't need to run 3 hours of super-anal tests every day, but it would be helpful to run 5 minutes of high-level tests regularly and then run the super-anal set just before I check code into CVS.

If all of your tests are at or near a particular point on the high-level->super-anal continuum, it isn't an issue now. But different devs will write tests at different levels of granularity, and the pool of tests will diverge from the happy medium you've probably struck now, and the "long time" your tests take to run will just get longer and longer and longer and...

These are my guesses, anyway. "I'm not a QA guy, but I play one in the forums sometimes..." In any case, I did talk with a friend about software testing in his company, and his major complaints about their situation have inspired this concern about levels.

It seems like it wouldn't be too hard to add some indication of granularity level to the tests, once we define the number of levels and have some indication of what they mean.
In reply to Matt Oquist

Re: Developers' test suite

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I do think we really need some way of grouping tests and perhaps indicating some level of granularity. Some tests are high-level and some are super-anal, and the rest are in-between. I don't need to run 3 hours of super-anal tests every day, but it would be helpful to run 5 minutes of high-level tests regularly and then run the super-anal set just before I check code into CVS.

Good thinking, and actually, I have already had to hack something in one place with some really slow tests. Amend what I said before:
  • The testcases themselves we have put in folders called 'simpletest', with filenames like text_xxx.php, so you have a /lib/simpletest/testdatalib.php
To
  • The testcases themselves will live in folders called 'simpletest', with filenames like testxxx.php or slowtestxxx.php. by default only the test files are run. There will be an option to run the slow tests too.
Crawling the directory tree and automatically finding all the testcases to run is definiltely the right way to do that. I say that beacuse it has been working for us, and it works well. And we already have options to start the crawl anywhere, for example in /mod/mymodule/, so it is easy to just run the tests related to your current development.

In reply to Tim Hunt

Re: Developers' test suite

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
No need to have separate files... why not just set a variable in the core files and add switch logic in the testxxxx.php files?
In reply to Martin Dougiamas

Re: Developers' test suite

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Because that is not how the simpletest framework does it.

The contents of the testxxx.php files is defined by the simpletest framework, and we don't want to change that. Under simpletest, (http://www.lastcraft.com/simple_test.php) the test file must define a class called testxxx with lots of test methods and it either runs the tests in that class or it doesn't.

Our contribution is just the code that crawls the directory tree, finds all the test cases, and runs them by calling a $this->addTestFile($file_path); method, so without major work, we either run all the tests in a file or not.

So to separate the everyday and the slow tests, having separate files is the most practical solution.
In reply to Tim Hunt

Re: Developers' test suite

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi,

Messaging me is the best way. smile More options in my profile.

Why *simple*test? I'd rather the names were simplified down to 'test', something like:

lib/testlib.php

lib/test/testdatalib.php

mod/forum/test/testlib.php

I'm probably slightly in favour of keeping the (redundant) 'test' prefix on the filenames to avoid possible confusion with the originals and to allow non-test files to also be put in those directories, but if these aren't really advantages then let's drop that too.
In reply to Martin Dougiamas

Re: Developers' test suite

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Why *simple*test?

Partly, because this is based on the open source simpletest framework.

More importantly, we decided that it would be bad to have a name clash. For example, we might want a module or block called 'test' one day, and if we did, it would have to live in a folder called 'test' and then we would have a folder called test that was not for testcases. That was the reason we chose a longer and more obscure folder name.

I definitely in favour of keeping the 'test' prefix on the test files. It means the filename describes the purpose of the file, like testdatalib.php.
In reply to Tim Hunt

Re: Developers' test suite

by Matt Oquist -
I agree. That's why I proposed "devtest[s]", to indicate that they're tests that developers run, and not code for a test-taking module or something.

As long as the name is clear and sane I have no further concern about it.
In reply to Martín Langhoff

Re: Developers' test suite

by David Scotson -

Talking about 'seed databases' would SQLite support help? I was wondering the other day whether the new XML database schema being discussed would provide SQLite support as an added bonus.

And while on the subject of automated testing, have any of the security minded people tried running the oedipus security scanner against Moodle? I had an urge to try it a few weeks ago but the download was temporarily removed while they sorted out some legal issues with a former employer, and I've not gotten round to it since. Looks very useful though.

In reply to Martín Langhoff

Re: Developers' test suite

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Incidentally, simpletest does also support web testing, so you can have both within the same framework. We are not using it as yet, so I'm unsure how it integrates with unit testing. Its support for web testing is described as 'primitive', but it does seem to support most necessary things (redirects, cookies etc).

http://www.lastcraft.com/web_tester_documentation.php

As I said we haven't used this yet so I'm definitely not offering an opinion on whether it is better or worse than [other system x]!

--sam
In reply to sam marshall

Re: Developers' test suite

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
OK, having written the post I got curious and tried it. It does fit in directly within the existing test framework. Here's an example:
require_once('simpletest/web_tester.php');

class test_learn_website extends WebTestCase {

const USERNAME='??',PASSWORD='??',SITE='d820-06e',
BASE='http://learn.open.ac.uk/';

function setUp() {
}

function test_sams() {
$this->get(self::BASE.self::SITE);
$this->assertTitle('Sign IN');
$this->setField('username',self::USERNAME);
$this->setField('password',self::PASSWORD);
$this->clickSubmit('Sign in');
$this->assertTitle('Course: The Challenge of the Social Sciences');
}

}
Username and password changed to protect the innocent smile [It was a dummy account, not mine. Even so.]

This tries to log into a Moodle course (course/view.php) via an Apache mod_redirect, which results in getting redirected to our single sign-on page and then redirected again about 387 times [unless they've changed it - I had to manually implement something that went through the process once and it was hugely tedious]. Then I made it fill in the username and password and sign in, which ends up creating some new cookies and (eventually) redirecting back to the Moodle site, automatically logging into that via our auth method, and viewing the course page.

Not very difficult I think! And neat that it can run in the same automated framework as our other tests. So anyway it's pretty cool, although obviously it doesn't handle Javascript, or browser-specific testing.

--sam