How to fail Jenkins if tests were not carried out?

We run TestNG tests using Gradle on Jenkins .

Job Configuration:
Assembly section → Call Gradle Script → Use Gradle Wrapper → Tasks:

 clean test -Dgroups=myTestNGTestGroupName 

In Jenkins Console gradlew.bat I see logs running gradlew.bat with certain parameters (one of them is -Dgroups=myTestNGTestGroupName )).

We have quite a few Jenkins tests and Selenium automation.
Since then, every day we check only unsuccessful tasks.

During the TestNG refactoring tests, the group name may change or a typo may occur.
If you changed the name of the test group in the test repository and forgot to update the Jenkins task:
0 tests are performed and work continues ( successfully completed ).

How can I tell Jenkins note that the assembly failed if no tests were performed?

+5
source share
1 answer

TestNG generates a testng-results.xml file each time a test is run.
(even if 0 tests were performed).

We can analyze this file. The easiest solution I've found is to use the Text Search Plugin
(which in my case has already been added to Jenkins )

I added Jenkins Text Finder to Post-build Actions as follows: text-finder-plugin

What the console output logs look like in Jenkins :

 BUILD SUCCESSFUL Total time: 42.105 secs Build step 'Invoke Gradle script' changed build result to SUCCESS Archiving artifacts Checking <testng-results skipped="0" failed="0" total="0" passed="0"> c:\jenkins\workspace\my-job-name\build\reports\tests\testng-results.xml: <testng-results skipped="0" failed="0" total="0" passed="0"> Build step 'Jenkins Text Finder' changed build result to UNSTABLE ... Finished: UNSTABLE 
+2
source

Source: https://habr.com/ru/post/1238191/


All Articles