What “command-line” build tool are you using? If it’s Maven, which is likely, then you can configure the Maven pom.xml to fail the build. Just go into the “Surefire” plugin configuration, and set “failIfNoTests” to true.
Generally, if the running of unit tests fail, you shouldn’t even run the SonarQube scan on that.
I agree with @David_Karr : you should fail the Jenkins build earlier than the SonarQube scan. Don’t rely on the SonarQube scan to catch it because SonarQube relies on the unit and coverage reports that are imported through your Sonar scanner.
For example, when you run mvn clean verify or mvn test, you’ll see this in the Maven logs:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ sonarscanner-maven-basic-artifact ---
[INFO] No tests to run.
You could check if No tests to run. occurs in the logs and fail the Jenkins build that way.
If you really want to check the Unit Tests count (assuming that you do import unit tests into SonarQube), you can add an “Overall Code” condition in your Quality Gate to check how many unit tests are imported: