i am trying to get some Javaquestions on the way and i think this Plugin is great.
The question that bugs me: is there a way to get some Junittest in there? If there is a way, how would i go about it? If not are there plans to integrate it? Do u have any alternatives?
Thx in advance
The good news is that you can pretty much set any question type you like by use of templates and user-defined question types. The not-so-good news is that it takes a while to get the hang of these.
I don't teach Java myself and have hardly used JUnit. But I've thrown together a question type that may perhaps point the way for you. It assumes the student submits a public class via the answer box (and perhaps attaches additional .java files, though I haven't tested that), while the question author supplies, as support files, a set of JUnit test files named BlahTest.java for any Blah. The question compiles all available .java files and, if all is OK, then runs all the JUnit files it can find. If any of the runs doesn't end in an "OK" line, the student gets zero marks; otherwise they get full marks. All JUnit output (bland unformatted text) is displayed. The JUnit jar files are attached as support files to the base question type so are automatically included in any questions using it.
Here are the only two tests I've run using it:
With normal CodeRunner questions the student gets to see exactly what tests they failed so they can fix their problems. I'm not sure how you wish to tell the student that sort of information if you're using JUnit; I leave that to you to deal with.
The attached question type (a PROTOTYPE and a trivial test of it) has had essentially zero testing; it certainly isn't ready for production use. I'm just providing it to help you on your way. The example was taken from the JUnit getting started page. Error conditions, multiple JUnit tests, and multiple student files are all untested.
It's also possible that some other Java CodeRunner users have developed suitable question types for you. Let's see if anyone responds.
If you do come up with a nice solution over time, please consider posting it back to this forum.
I am at the end of my wits. My sincerest apologies but i am not fast not very knowlegdeable in this field so maybe it is a really trivial error but i can't seem to get the solution on my own.
Do you have an idea what i am doing wrong?
Thx in advance
It sounds like you're pretty new to CodeRunner so it's probably best if you put the idea of a JUnit question type on hold until you've had a bit more experience. The prototype I gave you was something I threw together as in a hurry, but it's a rather difficult example and not a good starting point for learning. Furthermore, I just looked at it and saw a silly coding error which would give exactly the output you're getting if the test or program failed to compile. I've replaced the attachment in the the original post with a bug-fixed version, and I attach the updated version to this posting, too. You must delete the existing prototype before importing the new .xml or you'll get a prototype error. However, it's still not going to be useful in its present form, so I don't think it's worth proceeding until you're up to speed with writing templates, template debugging, defining new question types and a heap of other complexities. My apologies for tossing such a demanding exercise at you.
If you really really wish to proceed anyway, you'll need to read all the documentation on writing templates and authoring new question types. The example I gave you uses a combinator template grader, the most difficult type. The error message you're getting suggests that the program isn't generating any output, which is exactly what would happen with the first version I posted if anything went wrong (even a compile error - I had tested handling of compile errors while developing but made a last minute change which broke things).
To debug and develop the question type further (are you sure you want to do this?) you will need to proceed as follows:
- Create an empty directory for testing. Download the two support files from the prototype (hamcrest_core and junit 4.13 beta) into that directory.
- In the test question (calculator, or whatever), turn on the Template debugging checkbox.
- Run the test question (i.e. preview it and click Check).
- Copy the Debug source code from the run (assuming only one run took place) into a file tester.py within the test directory you set up.
- Run tester.py (you'll need python3 installed to run it). The output should be a JSON string containing the mark in an attribute fraction and the test output in an attribute prologuehtml.
- Debug as required.
- Copy the corrections back into the prototype's template, but make sure you don't clobber the Twig code that inserts the student's answer into the template.