Using Protractor, failing test cases using maven and then maven build should fail or not? - maven

Some of test cases are failed so due to that maven build is also failed .Just because of maven failure , Jenkins build is also failed.
So is it right or something is wrong in it?

In your Jenkins job you could run Maven with either of the following parameters:
-DskipTests=true to skip test execution entirely
-Dmaven.test.failure.ignore=true to ignore test failures
But if the tests are important (and they certainly should be :) then perhaps ignoring them (or not running them) is the wrong approach, perhaps you should instead fix the failed tests.

Related

how to get maven to run all tests but still fail build on compile error

Suppose I have a multi-module maven project. I want to run it in such a way that:
If a test fails, I still want to compile and test the next module. This sounds like a job for --fail-never, but see below.
If there are test failures, I don't really care if the build succeeds or fails. Ideally this would be configurable, but whatever.
If there are compiler errors, then the build should fail. I think this rules out "fail-never"?
You can use surefire parameter: maven.test.failure.ignore
mvn test -Dmaven.test.failure.ignore
With this options failing test will not fail build a module and finally whole build will have success result.

How to write a Maven plugin IT test that correctly fails its build, resulting in an overall pass?

When generating a skeleton Maven plugin from archetype, the new project includes a Maven project under the src/it directory. It is an integration it (hinted at by the it dir name) and fresh out-of-the-box it passes when run during Maven's integration-test phase.
There are nearly 10 such IT Maven projects, a subset of which intentionally result in BUILD FAILURE, and attendant verify.groovy scripts that ensure those builds fail for the correct reason. Ideally each IT test sub-build that fails for the correct reason results in that IT test passing, but by including any of these failing IT tests as part of the whole integration test suite causes the overall Maven run to fail as well, which is incorrect in my case.
How do I coax Maven to run those failing Maven sub-builds, ignore their build results, but honor the results of their Groovy verification scripts?
Edit: One IT test (disabled) is committed here.
If you like to write an integration test which is intended to fail as a result
you have to express this via the invoker.properties file like this:
invoker.buildResult=failure
The full description of the file can be found in the documentation.

Is it possible to have a maven build write a file when it fails?

I have a maven build running in a Jenkins job.
I need to do some post-processing stuff after the maven build but during the job, and so I'm running mvn with the -fn (--fail-never) option (jenkins will halt the job immediately otherwise).
The catch, of course, is that if the maven build step failed, I need to fail the job in a subsequent build step.
In the past I've done this sort of thing by writing a file to a certain location if the build failed, and then using the Ant task to fail the build. So this is the approach I'm going for.
Is it possible to get maven to write a file on build failure?
Instead of using the maven runner in Jenkin, you could execute the build as a shell script, then do something like...
mvn -q -fn clean verify || touch build_failed
I would suggest to use the configuration jenkins is capable of. Running a post-build-action in case of successful execution of the build and don't use --fail-never option.

Allow Maven build to continue if a specific JUnit test fails

My Maven build uses JUnit tests with the Surefire plugin. If a test fails, an mvn install will fail, which is normally desirable, but sometimes we wish to check in all the tests in advance for a feature which is not fully implemented. We would like be able to specify certain tests as "known failures" which will log their failure but not stop the build. Is there a way to do this?
(I'm aware we can set testFailureIgnore to true to not fail on any test failures, but we'd still like to fail on 'unexpected' test failures)

Setting up jasmine-maven-plugin failures to make jenkins unstable

I'd like to configure jasmine-maven-plugin to make jenkins unstable if a test fails but the only options appear to be:
set haltOnFailure true and have failures break the build
set haltOnFailure false and have failures reported in the logs but the build succeeds.
Is there a way to check the logs post-test and mark the build unstable?
Sam Hasler's answer only works for freestyle Jenkins jobs. We use Maven jobs and this configuration option of the JUnit Jenkins plugin is unavailable for Maven jobs. So I was looking for a more universal solution.
What we did in order to get it working is to reconfigure the Jasmine Maven plugin so as to
no longer halt the build upon test failures and
write the Jasmine test reports to target/surefire-reports where Jenkins expects to find them. This has the additional advantage that we now also see the failed Jasmine test in the build job alongside our Java tests.
<haltOnFailure>false</haltOnFailure>
<jasmineTargetDir>${project.build.directory}/surefire-reports</jasmineTargetDir>
Now our build jobs are yellow (unstable) as expected, no longer red (failed).
Found the answer myself!
I had to configure jenkins to also look at the jasmine junit report:
under Publish JUnit test result report add **/TEST-jasmine.xml to Test report XMLs, comma separated if there is something there already:
**/TESTS-TestSuites.xml,**/TEST-jasmine.xml

Resources