Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

How to stop OpenCover if some test cases in unit test fail. #168

Closed
huynguyencc opened this issue Aug 23, 2013 · 14 comments
Closed

How to stop OpenCover if some test cases in unit test fail. #168

huynguyencc opened this issue Aug 23, 2013 · 14 comments
Labels

Comments

@huynguyencc
Copy link

When I integrate OpenCover in Jenkin, I want to break build process if there are some test cases in unit test fail.
So is there any way to stop open cover immediately if some test cases fail ? I don't want output report in this case.

@sawilde
Copy link
Member

sawilde commented Aug 23, 2013

OpenCover will continue to run until the process it is 'profiling' stops/exits so it is up to the process itself to know when to stop and or abort early due to test error.

You didn't mention what test runner you are using so...

If you are using nunit-console then you can use its /stoponerror switch to terminate on the first error. There is a feature request for xUnit for similar behaviour.

I don't know of such a switch for MsTest.

@huynguyencc
Copy link
Author

I am using MsTest. It seems impossible to stop OpenCover when some test cases fail running in MsTest.

@sawilde
Copy link
Member

sawilde commented Aug 25, 2013

You could possibly wrap mstest in another process that could terminate mstest when it fails (i.e. process the mstest output as it happens) but OpenCover would not be able to do that for you.

@huynguyencc
Copy link
Author

I don't want terminate MsTest. I mean after running all unit test in MsTest , if there is any failed test case, Open Cover won't export coverage report.

@sawilde
Copy link
Member

sawilde commented Aug 26, 2013

I am confused are you you saying that if you get a failed test from mstest that
a) opencover does not generate a report or
b) that you do not want opencover to generate a report?

@huynguyencc
Copy link
Author

I mean I do not want opencover to generate a report in this case.

@sawilde
Copy link
Member

sawilde commented Aug 26, 2013

Why - if you don't want it just delete it

@huynguyencc
Copy link
Author

It's just my process. I think it is not a big problem. Just delete it if it's not necessary.
Thanks.

@sawilde
Copy link
Member

sawilde commented Aug 26, 2013

no worries - I hope you enjoy using OpenCover

@darkroastjava
Copy link

Hi there. I just stumbled over the same issue - I run OpenCover with MSTest as its target as part of a Jenkins build process. I would like to execute all tests AND generate the report, BUT after that the build job should be aborted and marked as failed (which happens when opencover exits with a non-zero code). Is such a configuration possible?

@sawilde
Copy link
Member

sawilde commented May 10, 2014

How are you running OpenCover? If using the <Exec /> task then you could possibly use the ExitCode and IgnoreExitCode to achieve what you want.

@darkroastjava
Copy link

@sawilde, thank you for the very quick response! I call opencover from the command line, using the "Execute Windows Batch Script" Jenkins build step. How can I find out whether at least one test failed using the Exec task (or the command line?)

@sawilde
Copy link
Member

sawilde commented May 16, 2014

I don't know much about Jenkins but you can use -returntargetcode to return the exit code of the target process as the exit code of OpenCover.

@darkroastjava
Copy link

Very good, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants