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

Junit question type

From MoodleDocs
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.

Screenshots

The following screenshots are to get a first idea of the question type. This way you can evaluate if it fits your needs. In section General Quiz settings, Given code for student and Load needed test file you can find more details about the teacher editing view.

In the following you can get an idea about:

  1. Teacher editing view
  2. Student view
    1. Output with compilation error
    2. Output with a bug in execution
    3. Output with correct execution
  3. Item analysis view
  4. Results overview view


1. Teacher editing view
In this example the student shall implement the faculty function discussed in class.

So junit edit 1.JPG So junit edit 2.JPG


2. Student view
In dependence of the test setting the student can see his/her compilation and/or execution outputs by using the submit button (in adaptive mode). Only after using the button Save without submitting the grade will be calculated.

So preview admin 2.JPG


In general there are three outputs possible.

1. Output with compilation error: So junit preview comp error.JPG

2. Output with a bug in execution: So junit preview exec bug.JPG

3. Output with correct execution: So junit preview exec correct.JPG


3. Item analysis view
A student took a test which consist of two junit-question-type questions.
In the first one the student solved the faculty function without compilation error and received 1 out of 3 points because the student passed 1 of 3 JUnit test cases created by the teacher.
In the second question the student implemented the addition-function. This compilation error is due to a missing semicolon in the JUnit test file the teacher has been uploading for this question. Therefor the student get 0/1 marks.

So junit itemanalysis.JPG


4. Results overview view
In this example eight students have taken this test.
In the first question 3/8 students didn't pass the last two test cases, 4/8 passed all test cases, 1/8 had a compilation error.
In the second question 8/8 students had a compilation error. We can assume that the test file of the teacher didn't compile correct.

So junit resultsOverview.JPG

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 needed 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