Greetings Richard,
We ran into an interesting problem with a Java question:
Our solution used a wildcard import, and this meant that some test code we had compiled okay when validating. Minus the wildcard import, the test code didn't compile, so some students who didn't use a wildcard in their answer had to add one for a test case, which felt odd.
I did a simple test:
- Create a java_class type question (which has no imports)
- Add a test case that requires an import, like ArrayList<String> x = new ArrayList<>();
- Don't enter an Answer, but tick the validate box
- It saves fine without complaining.
Once I add compiling code to the Answer, even commented out (//class X {}) then the issue with the test case is raised. But if you again remove all text from the Answer box and validate it saves fine.
I guess that a template ought to include required imports for the test cases, as we wouldn't really expect the Answer to contain imports for arbitrary tests. But it was odd that we didn't spot the problem earlier, in spite of validating our solution.
A side question is whether an empty Answer with validate ticked ought to compile in this case - an empty Java source code file is actually compilable, and validating an empty file would give a way of checking whether test cases require imports.
For the time being I've just made a note to self - take care with imports!
Anton