pysysjava.junittest¶
Support for compiling/running/validating JUnit test classes from PySys.
If you want to run a whole directory of JUnit tests as a single PySys test, create a PySys test which uses the
JUnitTest
class in place of run.py
.
For large or long-running JUnit suites it’s better to use the JUnitDescriptorLoader
(configured with a
pysysdirconfig.xml
file). This descriptor loader creates in-memory PySys test descriptors for each JUnit test
class found under the input directory (each of which is run using JUnitTest
). This allows each test class to run
in its own PySys worker thread (with its own JVM process, and its own separate output directory), and provides an
easier way to re-run failed JUnit classes just as you would for a normal PySys test. It means there is no need to
create separate pysystest.xml
files on disk for each test class, yet you can interact with them using the
full power of PySys.
Both approaches allow the stdout/err (for example log output) to be captured from each testcase, and reporting of
the (.java
) location and nature of any test failures, with colour coding (if coloured output is enabled), and
highlighting of actual vs expected comparison failure, to make it as easy as possible to read the output.
JUnitTest¶
-
class
pysysjava.junittest.
JUnitTest
(descriptor, outsubdir, runner)[source]¶ Bases:
pysys.basetest.BaseTest
A test class that compiles and runs one or more JUnit test suites.
This class requires the JUnit 5 console launcher, which itself supports running older JUnit 4 testcases - so whichever version you need, you should be covered.
To run a set of JUnit tests from a single PySys test, put the unit test .java files in the Input directory, and specify this class in the
pysystest.xml
:<data> <class name="JUnitTest" module="${appHome}/pysysjava/junittest"/> ... </data>
Compilation happens in
pysys.basetest.BaseTest.setup
(shared across all JUnit tests that use the same source directory), then execution inpysys.basetest.BaseTest.execute
and finally reads the resulting XML reports and adds outcomes for each testcase inpysys.basetest.BaseTest.validate
.There are 3 options for customizing the arguments that will be passed to the JUnit console launcher:
junitConfigArgs
should be used for configuration options (e.g.--config=
) that should always be used for these tests, typically configured in theuser-data
of the test or directory descriptor.junitSelectionArgs
should be used for--select-*
arguments that identify which tests are covered by this PySys tess, typically a descriptor’suser-data
. If not specified, selection arguments are automatically added for every package in the compiled classes directory.junitArgs
exists to provide a way to add one-off arguments runs on the PySys command line (in addition to the above arguments), e.g.pysys run "-XjunitArgs=-t MYTAG"
.
Any classpath requirements or runtime JVM arguments should be customized using the properties described in
pysysjava.javaplugin
such asjavaClasspath
andjvmArgs
.The JUnit process is given Java system properties for the PySys testcase Input/ directory (
pysys.input
), the test project root directory (pysys.project.testRootDir
), and if this PySys test has any modes defined, the current mode (pysys.mode
).-
junitConfigArgs
= ''¶ JUnit console launcher command line arguments needed to configure the JUnit tests, e.g.
--config key=value
.If needed, this should be set in the test descriptor
user-data
.See JUnit documentation for more information about the console launcher command line arguments.
-
junitSelectionArgs
= ''¶ JUnit console launcher command line arguments needed to select which JUnit tests are part of this PySys test, e.g.
--select-package=myorg.myserver
.If needed, this should be set in the test descriptor
user-data
. If not specified, selection arguments are automatically added for every package in the compiled classes directory.See JUnit documentation for more information about the console launcher command line arguments.
-
junitArgs
= ''¶ Extra JUnit console launcher command line arguments, which will be used in addition to any
junitConfigArgs
andjunitSelectionArgs
.This is usually not set in a test descriptor
user-data
but instead on the PySys command line with-X
.For example:
pysys run -XjunitArgs=a b "--config=foo=bar baz" c d e"
, or more realistically:-XjunitArgs=-tMY-TAG
(to run just the testcases with the specified JUnit tag).See JUnit documentation for more information about the console launcher command line arguments.
-
junitFrameworkClasspath
= ''¶ Must be set as either a project property or in the as test/directory descriptor
user-data
.The value is a list of jars (delimited by semicolon, os.pathsep, or newline), making up the JUnit framework and the
junit-platform-console-standalone
launcher jar.
-
junitTimeoutSecs
= 600.0¶ The time allowed in total for execution of all JUnit tests.
JUnitDescriptorLoader¶
-
class
pysysjava.junittest.
JUnitDescriptorLoader
(project, **kwargs)[source]¶ Bases:
pysys.xml.descriptor.DescriptorLoader
A
pysys.xml.descriptor.DescriptorLoader
that dynamically creates a separate PySys test descriptor for each .java JUnit test class found under theInput/
directory.To use this, create a
pysysdirconfig.xml
with a user-data elementjunitTestDescriptorForEach
.You may also wish to add a
junitStripPrefixes
user-data to strip off long common package names from your test classes and/or anid-prefix
to add a common testId prefix indicating these are JUnit tests.You can also use the
junit*
user-data options described inJUnitTest
and thejavaClasspath
andjvmArgs
described inpysysjava.javaplugin.JavaPlugin
.For example:
<pysysdirconfig> <id-prefix>MyJUnitTests_</id-prefix> <data> <user-data name="junitTestDescriptorForEach" value="class"/> <user-data name="junitStripPrefixes" value="myorg.mytestpackage, myorg2"/> <user-data name="javaClasspath" value="${appHome}/target/logging-jars/*.jar"/> <user-data name="jvmArgs" value="-Xmx256M"/> <user-data name="junitTimeoutSecs" value="600"/> <user-data name="junitConfigArgs" value=""/> </data> </pysysdirconfig>