Automated tests of the code with SimpleTest
turadg - June 24, 2009 - 20:00
| Project: | Quiz |
| Version: | 6.x-4.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Unit tests are an effective way to maintain reliable code. A test suite can automatically check the behavior of the code to see that it's performing as expected. This can free developers to experiment with bigger changes and lower the risk of committing changes that break the module or other developer's code.
The import/export code is quite new and has to interoperate with other systems, that may or may not have their own bugs. This may be a good section of the code to introduce unit tests to. We can use the Drupal SimpleTest module.

#1
Fixes a bug in the import code where the aiken style questions were not cleared from question to question.
Provides unit tests using the simpletest module for each of the currently supported input file types.
#2
Yes, unit testing on new modules would be great!
I started simpletests for the long answer module. I didn't do so well on the others that I added -- mainly because I think simpletest is a huge pain. But... it's the best tool we have for the job right now, so we should make use of it.
#3
dbesse, I tried this patch and it needs more work.
Results were, "30 passes, 29 fails, and 0 exceptions". Can you get it to pass all tests or are there bugs elsewhere in the module?
I was going to ask that you use the existing Examples directory as the source for tests, but I think it makes sense that the questions_import module have its own examples. In fact, I think the other Examples directory should move its contents into questions_import's. It might be argued that questions_export would use the same files, but there would be good reason for it to have its own files, since import then export isn't guaranteed to give the same data, char for char.
#4
Updated test files. Now had tests for native csv and aiken imports. Everything is now automated -- creates its own import files and then imports him rather than just using example files.
#5
dbesse, good progress. creating its own import files should make the tests easier to use.
some feedback:
- I changed "sites/default/files" to file_directory_path() so it would work on other sites
- the answers checking doesn't appear to work yet
- to help debug that, I included an identifier for the answer type on those assertions
- checking the data through HTML is brittle. checking the database would be better
I think the next work on this is to check the database instead of the HTML output. It should actually be easier than all the HTML parsing the current code has to do. And the HTML parsing can be broken out into a separate test, to test display of quizzes and questions instead of importing.
I'll leave this issue open until that's addressed. In the meantime I've checked your patch in with my edits, so be sure to update CVS before continuing.
#6
dbesse, I've checked in the newer tests you sent me by e-mail, along with the patch to quiz_questions.admin.inc. I think the tests are working well now so I'm going to mark this as "needs review" in case any co-maintainers have more input.
#7
@turadg or @dbessee Can you post the patches you are talking about in #6 so others can test?
#8
indytechcook, thanks for helping test. all the tests are in the CVS and thus the Quiz 4.x-dev distribution. Will that work for you?
#9
Great. Thanks turadg!
#10