Testing student written JUnit classes, a working custom question prototype

Testing student written JUnit classes, a working custom question prototype

von Jack Steel -
Anzahl Antworten: 0

Hiya,

One use case I have been wanting is testing student written JUnit test classes against both valid and invalid model classes to verify they have properly tested/covered the given code.

Our existing solution has been to require students to write an explicitly defined method name and then manually running that under the hood, and stubbing the assertX methods they're allowed to use. This obviously doesn't scale, as we need to stub each assert method they're allowed to use, and only allows them to write one test case.


I've written a JUnit test prototype that actually runs the given test class using the JUnit Console Launcher, and checks if the tests passed/failed.

This is ideal as it means students can write multiple @Test cases, and we can tell if they caught an issue that was introduced or not. They can use all JUnit 5 assertions, and it also supports precheck to ensure it compiles.


I've uploaded the exported prototype + an example. The documentation in the question prototype should give all the info you need, and I've included an example question that's using the prototype too.

Simply download this file and import into CodeRunner:

https://github.com/jackodsteel/coderunner-questions/blob/master/JUnitTesting/java_junit_testing_and_example.xml

You can also check out the source code and unit tests as Python files in that folder on Github.


Note: This question type uses JUnit 5, and isn't compatable with JUnit 4, although I could easily port a JUnit 4 version if anyone wanted.

Let me know if there's any issues.

Cheers.