Question Authors' Forum

Java_Program Test Cases

Re: Java_Program Test Cases

by Richard Lobb -
Number of replies: 0

The question type template defines the code that gets run. If you look at the template for your Java program question (click Customise) you'll see it's just 

{{ STUDENT_ANSWER }}

This means that the program that gets run is just whatever the student submitted. The test case code is ignored for this question type. In Python the question author can usefully add extra code to be run but that's not practicable with Java. With that question type all you can do is provide the standard input for each test and see if the output is what you wanted.

If you wish to give partial marks for partially correct output you can turn off all or nothing grading and use a regular expression grader (with the regular expression in the 'expected' field) to match a selected part of the output. A sequence of three such test cases would theoretically let you test how far the program got.

Frankly, though, I don't really recommend that approach. The regular expressions are likely to confuse the students. [And possibly the author too ... please note that the regular expression you provide is searched for in the output and isn't required to match the entire output unless you include the special characters to match at the start and end of the text.]

It's generally easier to set a sequence of questions that get the student to write a series of programs that build functionality one step at a time.

Alternatively use a Java method or Java class question type, which lets you test functionality in a finer-grained way. The test case code is not ignored for such questions - check out the templates to see how they work.