Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Junit question type.

Junit question type: Difference between revisions

From MoodleDocs
m (replaced correct modules and plugins link)
m (added link for cvs download)
Line 171: Line 171:


==See also==
==See also==
*[http://moodle.org/mod/data/view.php?rid=2104&page=187 Question type: JUnit] is a Modules and plugins database page for downloads and more information.
*Modules and plugins
**[http://moodle.org/mod/data/view.php?rid=2104&page=187 Question type: JUnit] - database page for downloads and more information
*Discussion threads:  
*Discussion threads:  
** Quiz module forum: [http://moodle.org/mod/forum/discuss.php?d=102690#p460596 New question type: Junit] - latest discussion
** Quiz module forum: [http://moodle.org/mod/forum/discuss.php?d=102690#p460596 New question type: Junit] - latest discussion
Line 178: Line 179:
* Tracker:
* Tracker:
** tracker entry in [http://tracker.moodle.org/browse/CONTRIB-689?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58527  Non-core contributed modules]
** tracker entry in [http://tracker.moodle.org/browse/CONTRIB-689?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58527  Non-core contributed modules]
* CVS:
** download the [http://cvs.moodle.org/contrib/plugins/question/type/sojunit/ code for this question-type-plugin] - download manually from cvs


[[Category:Contributed code]]
[[Category:Contributed code]]

Revision as of 16:18, 27 January 2009

For computer science courses this question type allows a student to type source code for a given interface in Java.

In case the student response compiles the response gets graded automatically. This way the teacher can save time for corrections. Otherwise the teacher needs to grade the student response manually (in Results-tab -> Overview-tab -> click on a students attempt -> a questions "Make comment or override grade"-link) in order to give partial scores instead of none.

After the quiz has been taken the given source code can be seen nicely syntax-highlighted in the gradings. In the quizzes "Results->Item analysis" the compiler or execution output get displayed for each students attempt. This way you can get a better overview about the problems of your students in coding.

There is also a security manager which checks for non-proper student-responses. This way you should not worry about the student messing up the system.

Installation guide

You may try out this question type with some given example files in the folder EXAMPLE_FILES.

1. Module Path:

   Put this module into this sub directory: moodle\question\type\

2. Compilation and execution:

   In config.php set the proper 'PATH_TO_JAVAC' and 'PATH_TO_JAVA'!
   Note: There is also a security manager which checks for non-proper student-responses. 
   This way you should not worry about the student messing up the system (polfile-file).

3. Syntax-Highlighting:

   If you don't have set Syntax-Highlighting already you should go through README_syntHighl.txt-file
   in order to get syntax highlighting configured. This way the source codes will be displayed syntax 
   highlighted after taking the quiz.

4. styles.css

   If you use Moodle 1.9 you won't need to do the following.
   If you use Moodle 1.8 do following for nice styling outputs:
   copy the code between the dashed line into moodle/theme/YOURUSEDTHEME(e.g. standardlogohighlighting)/geshi.css
   e.g. on the top
       ---------------
       /*********** styles for JUnit-question-type nice outputs*/        
       .que .studentscode {
         background: #ffa;
       }
       
       .que .compileroutput,
       .que .executionoutput{
         background: #acf;  /*ccc*/
       }
       /***********/
       ---------------

5. Module Documentation:

   In Moodle versions lower than 1.8.3 the linking to the local language files doesn't work properly.
   In order to get the linking work correct you need to replace some lines in two files
   (you may take a look at this discussion forum for details):
       In moodle/question/question2.php
           replace
           ---------------
           $streditingquestion = get_string('editingquestion', 'question');
           ---------------
           with
           ---------------
           list($streditingquestion,) = $QTYPES[$question->qtype]->get_heading();
           ---------------
       
       In moodle/question/type/questiontype.php
           replace
           ---------------
           function display_question_editing_page(&$mform, $question, $wizardnow){
               $name = $this->name();
               $strheading = get_string('editing' . $name, 'qtype_' . $name);
               if ($strheading[0] == '[') {
                   // Legacy behavior, if the string was not in the proper qtype_name
                   // language file, look it up in the quiz one.
                   $strheading = get_string('editing' . $name, 'quiz');
               }
               print_heading_with_help($strheading, $name, 'quiz');
               $mform->display();
           }   
           ---------------
           with
           ---------------
           /**
            * This method should be overriden if you want to include a special heading or some other
            * html on a question editing page besides the question editing form.
            *
            * @param question_edit_form $mform a child of question_edit_form
            * @param object $question
            * @param string $wizardnow is  for first page.
            */
           function display_question_editing_page(&$mform, $question, $wizardnow){
               list($heading, $langmodule) = $this->get_heading();
               print_heading_with_help($heading, $this->name(), $langmodule);
               $mform->display();
           }
           
           /**
            * Method called by display_question_editing_page and by question.php to get heading for breadcrumbs.
            *
            * @return array a string heading and the langmodule in which it was found.
            */
           function get_heading(){ //TODO new for language linking
               $name = $this->name();
               $langmodule = 'qtype_' . $name;
               $strtoget = 'editing' . $name;
               $strheading = get_string($strtoget, $langmodule);
               if ($strheading[0] == '[') {
                   // Legacy behavior, if the string was not in the proper qtype_name
                   // language file, look it up in the quiz one.
                   $langmodule = 'quiz';
                   $strheading = get_string($strtoget, $langmodule);
               }
               return array($strheading, $langmodule);
           }
           ---------------

6. Use in Moodle version < Moodle 1.9

   In file edit_sojunit_form.php-file change
       ---------------
       function validation($data, $files) {
         $errors = parent::validation($data, $files);
         return $errors;
       }
       ---------------
       to 
       ---------------
       function validation($data) {
         $errors = parent::validation($data);
         return $errors;
       }
       ---------------

General Quiz settings

It is required to leave the quiz in Adaptive Mode in order to get the compiler outputs displayed. In dependence of the Adaptive Mode used you need to leave "Penalty factor" to "0" in question-settings. This way the student won't get penalties subtracted when pressing the "Submit"-button in order to see if his/her code compiles.

For an "exam" and "exercise with grading" in quiz-options set e.g. "Attempts allowed" to "1 attempt" and "Grading method" to "Last attempt". This way the student can send in their final answer once using "Submit all and finish"-button but because of the Adaptive Mode they can "Submit" their code several times for compilation tests.

If several Junit-questions used in a quiz - for usability reasons it is recommended to put one question on a page at a time using "page breaks". It is also possible to put several Junit-questions on one page though.

The idea of which output to display at what time for which test type is as follows:


COMPILER OUTPUT:

  • Types: exams, exercise-sheets with grading and exercises without grading:
    • Gets displayed always.

EXECUTION OUTPUT:

  • Types: exams, exercise-sheets with grading:
    • Gets displayed always after the quiz has been taken.
    • Settings: In "Students may review" in quiz-options uncheck in "Immediately after the attempt" "Feedback" so that the execution output does not get displayed and the student does not get extracted or demotivated while taking an exam. In the "exercise-sheets with grading" the student should not get to see this until after the quiz.
  • Type: exercises without grading:
    • Display "immediately after the attempt" to student.
    • Settings: In "Students may review" in quiz-options in "Immediately after the attempt" leave "Feedback" selected in order to display also the execution output after an attempt to the student.

Given code for student

Make sure the class and method names used in "Given code for student" are identical with the ones in your test class you want to use for this question. Otherwise the student response won't be executed and you will have to grade each student response manually.

The class names need to be non-public in order to compile properly. At the same time this allows to use several classes to be used in one JUnit-test-file.

Load test file

In order to get an automatic grading for this question you need to create and implement a JUnit test-file. This file needs to match exactly the class and function names used in the source code written in the "Given code for student" HTML-editor.

The number of your implemented test cases need to match the number in "Default question grade". For each test case the student can get 1 point. If you have for example five test cases in your test-file you should set the "Default question grade" to "5". If the response of the student passes all test cases he/she will get 5 points out of 5. Otherwise each failed test case will subtract 1 point of the possible.

Features

  • Works with
    • Moodle 1.9 (tested at the end)
    • Moodle 1.8 (not tested at the end)
  • Language
    • English
    • German: prepared - needs to be completed

See also