repomate-junit4 Module Reference¶
This module reference is intended for developers contributing to
repomate-junit4 and should not be considered a stable API.
junit4¶
Plugin that runs JUnit4 on test classes and corresponding production classes.
Important
Requires javac and java to be installed, and having
hamcrest-core-1.3.jar and junit-4.12.jar on the local macine.
This plugin performs a fairly complicated tasks of running test classes from pre-specified reference tests on production classes that are dynamically discovered in student repositories. See the README for more details.
-
class
repomate_junit4.junit4.JUnit4Hooks[source]¶ -
act_on_cloned_repo(path)[source]¶ Look for production classes in the student repo corresponding to test classes in the reference tests directory.
Assumes that all test classes end in
Test.javaand that there is a directory with the same name as the master repo in the reference tests directory.Parameters: path ( Union[str,Path]) – Path to the student repo.Return type: HookResultReturns: a plug.HookResult specifying the outcome.
-
clone_parser_hook(clone_parser)[source]¶ Add reference_tests_dir argument to parser.
Parameters: clone_parser ( ConfigParser) – Theclonesubparser.Return type: None
-
_java¶
Utility functions for activities related to Java.
This module contains utility functions dealing with Java-specific behavior, such as parsing package statements from Java files and determining if a class is abstract.
-
repomate_junit4._java.extract_package(class_)[source]¶ Return the name package of the class. An empty string denotes the default package.
Return type: str
-
repomate_junit4._java.extract_package_root(class_, package)[source]¶ Return the package root, given that class_ is the path to a .java file. If the package is the default package (empty string), simply return a copy of class_.
Raise if the directory structure doesn’t correspond to the package statement.
Return type: Path
-
repomate_junit4._java.fqn(package_name, class_name)[source]¶ Return the fully qualified name (Java style) of the class.
Parameters: Return type: Returns: The fully qualified name of the class.
-
repomate_junit4._java.generate_classpath(*paths, classpath='')[source]¶ Return a classpath including all of the paths provided. Always appends the current working directory to the end.
Parameters: Return type: Returns: a formated classpath to be used with
javaandjavac
-
repomate_junit4._java.is_abstract_class(class_)[source]¶ Check if the file is an abstract class.
Parameters: class – Path to a Java class file. Return type: boolReturns: True if the class is abstract.
-
repomate_junit4._java.javac(java_files, classpath)[source]¶ Run
javacon all of the specified files, assuming that they are all.javafiles.Parameters: Return type: Returns: (status, msg), where status is e.g.
Status.ERRORand the message describes the outcome in plain text.
-
repomate_junit4._java.pairwise_compile(test_classes, java_files, classpath)[source]¶ Compile test classes with their associated production classes.
For each test class:
- Find the associated production class among the
java_files
2. Compile the test class together with all of the .java files in the associated production class’ directory.
Parameters: Return type: Returns: A tuple of lists of HookResults on the form
(succeeded, failed)- Find the associated production class among the
_junit4_runner¶
-
repomate_junit4._junit4_runner.get_num_failed(test_output)[source]¶ Get the amount of failed tests from the error output of JUnit4.
Return type: int
-
repomate_junit4._junit4_runner.parse_failed_tests(test_output)[source]¶ Return a list of test failure descriptions, excluding stack traces.
Return type: str