New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publishing test results with failed tests does not fail the build #1268
Comments
You can mark the Publish Test Results task as Always Run and it will run even for a failed build. |
@chrisrpatterson Your response is unrelated to @strtdusty's issue. The issue is that if a test fail, the "build" is still marked as successful. The successful build contains a failed test, sure, but it will go unnoticed so it's almost irrelevant. |
+1 for this. I want to use the VSTS build system for our mobile projects but back it via Jenkins jobs as the Xcode support is somewhat lacking for my needs. My problem is that I have to mark the Jenkins job as unstable as I can only download artefacts (my junit results) from the "last successful build". This then means that my build appears to have succeeded if the user doesn't actually click into the build to investigate. |
how did you resolve this ? i am having similar issue. |
I used @chrisrpatterson 's suggestion. Our builds end up being marked as failed though which is correct. |
Why this is marked as closed? Although problem is resolved for the original request, the issue Publishing test results with failed tests does not fail the build is still not resolved as @liamnichols mentioned. Here are the steps to reproduce:
Expected result: Actual result: Solution proposed above only works if you run the tests as a previous build step. But it is still impossible to fail the build purely depending on the published results. Why is this important? If you have your build running outside of TFS bubble and just "publish" the results of the tests, then you still want to know a status of the build. |
@chrisrpatterson Can you please re-open this issue given @asinitson's rationale? |
There should at least be a checkbox for selecting whether the published test results can fail the build. |
I'm running two different test suites and I am able to fail the build with the test task itself for only one of them but not for the other. I'd like to be able to rely on the Publish Test Results task to mark a build failure if any of the tests it has published have failed. |
This is also a problem for Javascript tests/linting. My jshint/jscs failures are reported in the Tests tab, but the "npm test" and "Publish Test Results" tasks pass. |
Hey, everyone! Since original bug reporter has his problem solved and this bug report is closed, I guess it makes sense to add another bug report. @chrisrpatterson: Is anybody looking at the comments for this closed bug report? Are you considering re-opening it? I will wait a day or two for the reply and then create another report, so we at least would have some kind of statement: "won't fix" or "planned in some future release". |
User voice is probably a better place for this feedback. I'll re-open and assign to the appropriate team to see the feedback. This repo isn't used to track feature requests, so I would expect the issue to get closed again. |
@ericsciple I think this is a bug, not a feature request. Do you track bugs in this repo? At any rate, I suggest making it clear in your README that the UserVoice (link?) is the primary place for feature feedback. I certainly didn't know that--others won't either. You could even consider disabling the issues tab if truly no one is checking these. Otherwise, it might be good to do at least a weekly review or risk appearing like Microsoft doesn't care about this repo. Just a friendly suggestion :) |
Is the solution to this from @chrisrpatterson not correct. I have this solution working for karma tests which fail yet still return the test results. Note: Also if running tests where don;t force a clean checkout. Ensure that there is a task to remove the test and coverage folders prior to running the tests otherwise the Publish task step will pick up the xml test results from a previous test |
@ncunning Interesting, I didn't know the Command Line task allowed "Fail on Standard Error". My workaround was to use/create "reporters" specific to VSTS (jscs-reporter-vso, jshint-vso-reporter) and to manually parse C# TRX files. Now, if a test failure is detected, logging commands are written to stdout to fail the build. I think using the logging commands/Command Line task (as suggested by @ncunning) is the solution to this issue. It's more clear to users that their tests failed when the testing step fails vs. the publishing step. The only downside is that the test results need to be parsed twice: once to determine if there are failing tests and once in Publish Test Results. |
@pakdev When i look at the output it is the actual testing step which fails. The Publishing Tests Results allow the Tests section to display the charts and failed test etc.. |
@ncunning Sorry, I meant our solutions are better than failing the Publish Test Results task as suggested by this issue. I've edited my response to reflect this. |
The purpose of Publish Test Results Task is to report the test results, hence if task is able to report all the results successfully it is marked as success even if it there were test failures. If the test execution does not return failure for a failed test, here is a sample that queries the failed tests and returns failure, which you can refer to drive the expected behavior https://github.com/ManojBableshwar/VstsTestRestApiSamples/blob/master/QueryTestRunResultsAndFailBuild/QueryTestRunResultsAndFailBuild.cs |
As suggested above, closing the issue. |
@Nekobravo please create a new issue |
The new .NET Core VSTS tasks for dotnet test allow you to publish tests as part of the one step. If you can't use them go with @chrisrpatterson suggestion Publish Test Results task as Always Run, then add the following command line task to fail the build:
|
A key detail that I hadn't thought about is that my test runner script needed to exit with a non-zero status code when any tests failed. Because I was running two sets of tests with the same bash script, that wasn't always the case if the second set of tests all passed. I found a similar workaround to what @DalSoft suggests here: http://hermit.no/conditionally-fail-build-pull-requests-tfs-vsts/. In YAML the workaround from the linked blog post essentially looks like this (I opted to make it always fail, not just on PR's):
|
This keeps coming up, so let me try to clarify the expected behavior here:
I hear people suggesting that uploading failed tests with "Publish Test Results" should cause that step to fail (and therefore cause the build to fail). I would argue that failing the "Publish" step would be reporting the failure in the wrong place if the failure is actually in your test run. A failed test run should fail the build on its own. It shouldn't require "Publish Test Results" to detect the failure. I admit, it might take a minute to figure out the "Run always" setting. But the intent of having build steps is to localize failures. Feel free to speak up if you still disagree, but I hope that helps clear things up. |
@brcrista whilst technically correct as the publish hasn't failed the test task did - I think the confusion is because It's counter-intuitive to see green on the last build step if there is a failure. I expect to see red in the place that reports if my tests failed. This is why the dotnet core task runs and publishes the tests together in one step. |
@brcrista: Technically correct does not equal useful. It might be that some people were confused. For me there was never any confusion. But maybe I missed some kind of guideline in the spirit of "task should only fail with single condition"? Let me reiterate the use case:
The outcome I wish I could have: Actual outcome: Now to the solution:
I even thought about parsing the test result file and deciding on the outcome, but that seems especially ridiculous if you consider that "Publish Test Results" already parses test results and has all the information needed to signal pass/fail. |
Ok, I hear you. Right now, Publish Test Results doesn't parse the results files, it just uploads them to the service, which does the actual processing when it displays your results on the "Tests" tab (much like publishing artifacts): That's why this suggestion would be a big change to the task. I think the reason we haven't done the work for a special "Validate Test Results" task, or adding this functionality to Publish, is that most workflows do run and publish tests in the same job, and the step that runs the tests is usually the easiest and fastest place to fail the build. It already has the knowledge and no files need to get parsed. It sounds like there are some workflows that want this step. Sorry to point you somewhere else, but https://developercommunity.visualstudio.com/ is where we'd like you to suggest this -- we prefer to use Issues to track tasks that not working as intended. Click "Suggest a feature:" That said, here's a short PowerShell script that will find the number of failures in a JUnit XML (even works on hosted *nix agents 😉): - powershell: |
$junitXml = "junit/unit-test.xml"
$(Get-Content $junitXml | Out-String) -match 'failures="(.*?)"'
if ($matches[1] -eq 0)
{
Write-Host "No test failures"
}
else
{
# note that this will produce $LASTEXITCODE=1
Write-Error "$($matches[1]) tests failed"
}
displayName: Check for test failures |
Issue related : microsoft/azure-pipelines-tasks#1268 Adding a checkbox option : Fail if there are test failures. ![image](https://user-images.githubusercontent.com/13175100/49723461-dc831800-fc8c-11e8-86f7-0bdaab7b0eaf.png) This PR relates to setting the task result to failed if the option is marked and there are test failures.
…are found (#9036) Issue related : #1268 Adding a checkbox option : Fail if there are test failures. ![image](https://user-images.githubusercontent.com/13175100/49723461-dc831800-fc8c-11e8-86f7-0bdaab7b0eaf.png)
Is this new feature live in VSTS? I'm not seeing the new checkbox. When will it be available? |
@benken-parasoft, it will be available with next Azure Devops deployment (3 weeks away) |
Hi, it isn't live yet and will be available in few weeks as we have deployment freeze for the holiday season. Sorry for the delay. |
Why has this been closed - this isn't available yet |
@hisuwh It's getting rolled out. It should be available within 2-3 days for everyone. |
Ok thanks. You're documentation has already been updated which adds to the confusion |
I'm using the YAML pipelines how will I know when I can use this feature? |
Please follow this - https://docs.microsoft.com/en-us/azure/devops/release-notes/ |
Just found out a bunch of our tests had been failing for weeks but we didn't know because the build was green, hiding a bug in our production code. So infuriating. Our build ran "dotnet test" a bunch of times manually in a PowerShell task because the tests need environment variables set, and the task ignored the exit codes of all but the last call to "dotnet test". Good to see "Fail if there are test failures" appear as an option, but seems to just be inviting mess-ups by not having it checked by default. Maybe checked by default in the next version of the Publish Test Results task? |
@Huffers while we agree with "by default" it should be enabled, it breaks the compat scenario and cause more customer issues. |
I am using xunit test through DNX. For each project we generate a test result xml file and use the "publish test results" task to publish the results to the build. The results get published correctly and we can see that some tests failed. When tests fail, however, the build is not marked as failed. I could fail the build when running xunit, but the results would not get published. Is there a way for the build to look at the published test results and fail if there are test failures?
The text was updated successfully, but these errors were encountered: