diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 1a583bfa2..e4333a266 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4282,26 +4282,65 @@ def testng(parser, xml_parent, data): Requires the Jenkins :jenkins-wiki:`TestNG Results Plugin `. :arg str pattern: filename pattern to locate the TestNG XML report files + (required) :arg bool escape-test-description: escapes the description string associated with the test method while displaying test method details (default true) :arg bool escape-exception-msg: escapes the test method's exception messages. (default true) + :arg bool fail-on-failed-test-config: Allows for a distinction between + failing tests and failing configuration methods (>=1.10) (default + false) + :arg bool show-failed-builds: include results from failed builds in the + trend graph (>=1.6) (default false) + :arg int unstable-skips: Build is marked UNSTABLE if the number/percentage + of skipped tests exceeds the specified threshold (>=1.11) (default 100) + :arg int unstable-fails: Build is marked UNSTABLE if the number/percentage + of failed tests exceeds the specified threshold (>=1.11) (default 0) + :arg int failed-skips: Build is marked FAILURE if the number/percentage of + skipped tests exceeds the specified threshold (>=1.11) (default 100) + :arg int failed-fails: Build is marked FAILURE if the number/percentage of + failed tests exceeds the specified threshold (>=1.11) (default 100) + :arg str threshold-mode: Interpret threshold as number of tests or + percentage of tests (>=1.11) (default percentage) - Example: + Full Example: - .. literalinclude:: /../../tests/publishers/fixtures/testng001.yaml + .. literalinclude:: /../../tests/publishers/fixtures/testng-full.yaml + :language: yaml + + Minimal Example: + + .. literalinclude:: /../../tests/publishers/fixtures/testng-minimal.yaml :language: yaml """ reporter = XML.SubElement(xml_parent, 'hudson.plugins.testng.Publisher') - if not data['pattern']: - raise JenkinsJobsException("A filename pattern must be specified.") - XML.SubElement(reporter, 'reportFilenamePattern').text = data['pattern'] - XML.SubElement(reporter, 'escapeTestDescp').text = str(data.get( - 'escape-test-description', True)) - XML.SubElement(reporter, 'escapeExceptionMsg').text = str(data.get( - 'escape-exception-msg', True)) + reporter.set('plugin', 'testng-plugin') + valid_threshold_modes = ['number', 'percentage'] + threshold_mode = data.get('threshold-mode', 'percentage') + + mappings = [ + ('pattern', 'reportFilenamePattern', None), + ('escape-test-description', 'escapeTestDescp', True), + ('escape-exception-msg', 'escapeExceptionMsg', True), + ('fail-on-failed-test-config', 'failureOnFailedTestConfig', False), + ('show-failed-builds', 'showFailedBuilds', False), + ('unstable-skips', 'unstableSkips', 100), + ('unstable-fails', 'unstableFails', 0), + ('failed-skips', 'failedSkips', 100), + ('failed-fails', 'failedFails', 100), + ] + helpers.convert_mapping_to_xml( + reporter, data, mappings, fail_required=True) + + if threshold_mode == 'number': + XML.SubElement(reporter, 'thresholdMode').text = str(1) + elif threshold_mode == 'percentage': + XML.SubElement(reporter, 'thresholdMode').text = str(2) + else: + raise InvalidAttributeError( + 'threshold-mode', threshold_mode, valid_threshold_modes) def artifact_deployer(parser, xml_parent, data): diff --git a/tests/publishers/fixtures/testng-full.xml b/tests/publishers/fixtures/testng-full.xml new file mode 100644 index 000000000..0b70e24e0 --- /dev/null +++ b/tests/publishers/fixtures/testng-full.xml @@ -0,0 +1,17 @@ + + + + + **/testng-results.xml + false + false + true + true + 50 + 25 + 75 + 66 + 1 + + + diff --git a/tests/publishers/fixtures/testng-full.yaml b/tests/publishers/fixtures/testng-full.yaml new file mode 100644 index 000000000..4b1259714 --- /dev/null +++ b/tests/publishers/fixtures/testng-full.yaml @@ -0,0 +1,12 @@ +publishers: + - testng: + pattern: "**/testng-results.xml" + escape-test-description: false + escape-exception-msg: false + fail-on-failed-test-config: true + show-failed-builds: true + unstable-skips: 50 + unstable-fails: 25 + failed-skips: 75 + failed-fails: 66 + threshold-mode: number diff --git a/tests/publishers/fixtures/testng-minimal.xml b/tests/publishers/fixtures/testng-minimal.xml new file mode 100644 index 000000000..1eb92b583 --- /dev/null +++ b/tests/publishers/fixtures/testng-minimal.xml @@ -0,0 +1,17 @@ + + + + + **/testng-results.xml + true + true + false + false + 100 + 0 + 100 + 100 + 2 + + + diff --git a/tests/publishers/fixtures/testng-minimal.yaml b/tests/publishers/fixtures/testng-minimal.yaml new file mode 100644 index 000000000..ee317bfbe --- /dev/null +++ b/tests/publishers/fixtures/testng-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - testng: + pattern: "**/testng-results.xml" diff --git a/tests/publishers/fixtures/testng001.xml b/tests/publishers/fixtures/testng001.xml index e33608c42..ec8de6dec 100644 --- a/tests/publishers/fixtures/testng001.xml +++ b/tests/publishers/fixtures/testng001.xml @@ -1,10 +1,17 @@ - + **/target/surefire-reports/testng-results.xml - False - True + false + true + false + false + 100 + 0 + 100 + 100 + 2