Package: repomate-junit4
repomate-junit4, a JUnit 4.12 test runner plugin forrepomateThis is a plugin forrepomatethat runs
JUnit4 test classes on production classes in a cloned student repo.Requirementsrepomate-junit4has a few non-Python dependencies.javamust ba available from the command line.javacmust be available from the command line.In other words, install aJDKversion that is compatible with the files
you intend to test!junit-4.12.jarmust be available on theCLASSPATHvariable, or configured
(seeAdded CLI argumentsandConfiguration file).hamcrest-core-1.3.jarmust be available on theCLASSPATHvariable or
configured in order to make use ofhamcrestmatchers.Thehamcrestandjunitjars ar available from Maven Central:wgethttp://central.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
wgethttp://central.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jarInstallThe recommended way to installrepomate-junit4is withpip.python3-mpipinstall--userrepomate-junit4The plugin itself does not actually requirerepomate, but it is fairly
useless without. Ifrepomateandrepomate-junit4are both installed in the
same environment, thenrepomateshould just findrepomate-junit4.
Forrepomateto actually userepomate-junit4, it must be configured
in therepomateconfiguration file. Refer to therepomatedocsfor information on the configuration file and its expected location, and theConfiguration filesection here for info on what you
need to add to it.UsageTerminology and conventionsThis is terminology added in excess to that which is defined in therepomatedocs.
For brevity, some conventions expected byrepomate-junit4are baked into
these definitions.Production class:A Java file/class written in the student repo.Test file: A file ending inTest.javawhich contains a test class for
some production class. If the students are supposed to write a file calledLinkedList.java, the corresponding test class must be calledLinkedListTest.java.Test dir: A directory named after a master repo, containing tests for
student repos based on that master repo. Should contain test files
as defined above.Reference tests directory (RTD): A local directory containing subdirectories
with reference tests. Each subdirectory should be a test dir as defined above.Security aspectsThere are some inconvenient security implications to running untrusted code on
your own computer.repomate-junit4tries to limit what a student's code can
do by running with a very strict JVMSecurity Policy.
This is enforced by the JavaSecurityManager.
The policy used looks like this:// empty grant to strip all permissions from all codebases
grant {
};

// the `junit-4.12.jar` needs this permission for introspection
grant codeBase "file:{junit4_jar_path}" {{
    permission java.lang.RuntimePermission "accessDeclaredMembers";
}};
"""This policy disallows student code from doing most illicit things, such as
accessing files outside of the codebases's directory, or accessing the network.
The{junit4_jar_path}is dynamically resolved during runtime, and will lend
the actualjunit-4.12.jararchive that is used to run the test classes
sufficient permissions to do so.This policy seems to work well for introductory courses in Java, but there may
be snags because of how restrictive it is. If you find that some permission
should definitely be added, pleaseopen an issue about itThere are plans to add the ability to specify a custom security policy, but
currently, your only choice is to either use this default policy or disable it
with--disable-security.Important:The security policy relies on the correctness of the Java
SecurityManager. It is probably not bulletproof, so if you have strict
security requirements, you should probably only run this plugin inside of a
properly secured environment (for example, a virtual machine).Added CLI argumentsrepomate-junit4adds four new CLI arguments to therepomate clonecommand.-rtd|--reference-tests-dirPath to the RTD.Requiredunless specified in the configuration file.-junit|--junit-pathPath to thejunit-4.12.jarlibrary.Requiredunless specified on theCLASSPATHvariable, or in the
configuration file.-ham|--hamcrest-pathPath to thehamcrest-core-1.3.jarlibrary.Requiredunless specified on theCLASSPATHvariable, or in the
configuration file.-i|--ignore-testsA whitespace separated list of test files (e.g.LinkedListTest.java) to
ignore. This is useful for example if there are abstract test classes in
the test dir.--disable-securityDisable the seurity policy.-v|--verboseDisplay more verbose information (currently only concerns test failures).Long lines are truncated.-vv|--very-verboseSame as-v, but without truncation.Configuration fileFirst and foremost,junit4must be added to thepluginsoption under the[DEFAULTS]section in order to activate the plugin,see details here.
The--hamcrest-path,--junit-pathand--reference-tests-dirarguments can
be configured in the standardrepomateconfiguration fileby adding the[junit4]section heading. Example:[DEFAULTS]plugins=junit4[junit4]reference_tests_dir=/absolute/path/to/rtdjunit_path=/absolute/path/to/junit-4.12.jarhamcrest_path=/absolute/path/to/hamcrest-core-1.3.jarImportant:All of the paths in the config must be absolute forrepomate-junit4to behave as expected.