Test Cases Not Working

Re: Test Cases Not Working

by Richard Lobb -
Number of replies: 0
Thanks for sharing your question and for the offer to add to the repository. I now see what you're trying to achieve and why you are finding the testing problematic.

As a school teacher with small classes it can be convenient to ask questions with a somewhat vague specification (e.g. "write a class that does something interesting and has at least two methods, where one method calls the other"). You then manually check each student's code and offer one-on-one advice. 

With CodeRunner, however, you need to ask testable questions, where you can run code that definitively marks a students's code right or wrong. That means the specification of the question needs to be totally explicit about all the details. For example, rather than "a method that adds two numbers" you might have to say "a method with a signature int addNumbers(int n1, int n2) that returns the sum of its parameters n1 and n2". Or it might instead say that the function is of type void and prints the sum in some specified format.

Here are three questions that call for such a method:

1. Using the Java method question type:



2. Using the Java class question type:



3. Using the Java program question type:



The three approaches have different trade-offs. None is perfect. The last one is the easiest in many ways because no code is being hidden in the template, but has the disadvantage that the output when running from the keyboard includes echoing of the input as it is read, which doesn't happen when running from an input file, as with CodeRunner. [With Python we can simulate that in the python3_w_input question type, but I don't know of an easy way to do that in Java.]

Note that none of these methods lets you "see inside" the implementation that the student has chosen. So you can't easily ask students to, for example, use two methods where one method calls the other. [You could test the internal behaviour using Mocking - see https://www.unlogged.io/post/java-mocks-a-guide-to-mocking-in-java - but that's a couple of orders of magnitude more complicated.]

I attach a zip of the xml exports of the above three questions.