Test cases : arguments from the command line

Test cases : arguments from the command line

by Esther Gago -
Number of replies: 3

I would like the students to complete a Java application with arguments from the command line, and I couldn't find a way to do a test to validate it: where do I have to write the arguments in the test cases boxes?

Thank you!

In reply to Esther Gago

Re: Test cases : arguments from the command line

by Richard Lobb -
This is not something you can do out of the box. You need to write your own question type, typically by scripting in Python. If you create a new question of type 'multilanguage' and click 'customise', you can see the sort of things you need to do.

I created a new prototype by cutting back the multilanguage question type to run only Java, and changing the execute command to use the TEST.testcode field of the testcase as a bash command line. The command line must include a substring <classname> that is replaced by the name of the main class submitted by the student. I attach that prototype and the one-and-only question that has ever been written to use that new question type. Since this new question type has had a grand total of 2 minutes testing, expect to have to do some debugging or tuning!

In reply to Richard Lobb

Re: Test cases : arguments from the command line

by Esther Gago -
Thank you very much for your time and information! And for your quick answer.
The thing is that I would like the students to complete a java code that I write in the "answer box preload" of a Java Program CodeRunner question.
They have to write five or six lines of a class, that includes this code


public static void main(String[] args)   {

if (args != null && args.length > 0)
{
System.out.println ("Prime numbers up to " + args[0] + ":");
for (int i = 1; i < Integer.parseInt(args[0]); i++)
if (isPrime(i))
System.out.print (" " + i);
}

So, in the test cases I would like to verify if they complete properly the isPrime() method.
The information you give me, is the one I need to do that?? Sorry for asking, but is the first time I would use templates and things like that in a question.
In reply to Esther Gago

Re: Test cases : arguments from the command line

by Richard Lobb -
There are three standard Java question types: write-a-method, write-a-class and write-a-program. The file PROTOTYPE_java_prog_bash_cmd.xml that I gave you in the previous posting implements a fourth question type: a variant of write-a-program that lets you specify the exact command line with which to run the program. But it's relatively untested and its only value would be when the question is explicitly focused on processing command line arguments.

In your case, where you just want students to write the isPrime(i) method, the write-a-method question type would seem to be what you want.

The quiz Some C and Java questions should give you some ideas on what you might do. The questions used there are included in the export file simpledemoquestions.xml on the GitHub repo.