FineCodeCoverage icon indicating copy to clipboard operation
FineCodeCoverage copied to clipboard

Results Not Available For Classes That Have Only async Methods

Open slagesse-epic opened this issue 5 months ago • 17 comments

If all methods in a class are async, then FCC does not seem to detect the class at all or include coverage information for that class in the output.

If any method of the class is not async, then FCC does detect the class and include coverage in the output, including for any async methods that might be in the class.

For example, FCC does not seem to properly report coverage when testing the following class:

public class AsyncCalc {

	public static async Task<int> Add(int a, int b)
	{
		return a + b;
	}

	public static async Task<int> Subtract(int a, int b)
	{
		return a - b;
	}

}

slagesse-epic avatar Jul 14 '25 21:07 slagesse-epic

Albeit from a fork of FCC

Image

Have you turned off showing coverage when a class is fully covered ?

tonyhallett avatar Jul 14 '25 21:07 tonyhallett

HideFullyCovered | Set to true to hide classes, namespaces and assemblies that are fully covered.

( just in case ) Hide0Coverage | Set to true to hide classes, namespaces and assemblies that have 0% coverage.

tonyhallett avatar Jul 14 '25 21:07 tonyhallett

Hm, that's definitely not what I'm seeing.

I have both of those settings set to false.

slagesse-epic avatar Jul 14 '25 23:07 slagesse-epic

Then the sut assembly has likely not been included or the class itself has been excluded.

In the assembly with the class with only async methods are you receiving coverage for other classes ?

If you are using the option MsCodeCoverage - Yes and have not provided your own runsettings then you can check the generated .runsettings file within a sub directory of your test project's bin/Debug/../fine-code-coverage/coverage-tool-output If not MsCodeCoverage then the FCC output window pane shows the command line arguments used to run the coverage.

You should check the FCC output window pane regardles.

If this is not sufficient for you to determine why you have no coverage then you need to provide a minimal reproducible solution that exhibits this behaviour and provide the FCC visual studio options that you have set.

tonyhallett avatar Jul 14 '25 23:07 tonyhallett

Note that IncludeReferencedProjects is not transitive.

tonyhallett avatar Jul 14 '25 23:07 tonyhallett

You need the pdb for the assembly you want covered. Are you running tests in debug or release ?

tonyhallett avatar Jul 14 '25 23:07 tonyhallett

Thanks for the assistance. Your project does not compile for me without changing the signature of WhenAllAsync to

public async Task WhenAllAsync()

After making that change, I am seeing the same behavior with your project.

Here is the project where I am producing this. I have two classes in the assembly under test, one that uses async methods and one that uses sync methods. The async class has source code showing as "not included' while the sync class is showing coverage as expected. FCCBug.zip

Here is my FCC output including the generated runsettings file (note that I have redacted system path and user information):

fcc_output.txt

Here are my VS settings as screenshots (please let me know if there is a better way to export settings):

Image Image Image Image Image Image

slagesse-epic avatar Jul 15 '25 17:07 slagesse-epic

Perhaps this is the issue - from the readme

The old coverage was based upon every test. Ms code coverage is coverage from the tests you select in the test explorer.

tonyhallett avatar Jul 15 '25 17:07 tonyhallett

I am seeing this behavior even when asking the Test Explorer to run all tests.

slagesse-epic avatar Jul 15 '25 17:07 slagesse-epic

I am out so will have a look later.

Can you screenshot the report and the editor colouring

tonyhallett avatar Jul 15 '25 18:07 tonyhallett

Here is the coverage report:

Image

Here is the AsyncCalc class:

Image

Here is the Calc class (Add is sync, Subtract is still async but is correctly showing as covered):

Image

slagesse-epic avatar Jul 15 '25 19:07 slagesse-epic

"I am seeing this behavior even when asking the Test Explorer to run all tests."

The AsyncTest class tests are not being run.

Image

As you are using Microsoft.VisualStudio.TestTools.UnitTesting

Image Image

tonyhallett avatar Jul 16 '25 07:07 tonyhallett

My apologies, the access level of AsyncCalc should be public and not internal. However, if I change AsyncCalc to public from internal, the tests run:

Image

But I am still not seeing code coverage:

Image

Here is the corrected solution:

FCCBug2.zip

slagesse-epic avatar Jul 16 '25 15:07 slagesse-epic

I think the issue is with report generator not understanding the cobertura report that is generated from microsoft code coverage. Report generator is used for resolving names and producing the final cobertura report that FCC uses. Unfortunately with the version of report generator that FCC is currently using ( which cannot be changed easily as we are embedding their HTML report which is no longer supported in WebBroswer form ) this is indeed an issue and I apologize for being flippant before.

As a workaround you can set RunMsCodeCoverage No.

A better report that is up to date with report generator will be available soon.

tonyhallett avatar Jul 16 '25 23:07 tonyhallett

https://github.com/danielpalme/ReportGenerator/releases/tag/v5.3.5

tonyhallett avatar Jul 16 '25 23:07 tonyhallett

Wonderful, thanks for the help and glad to hear a fix is on the way!

slagesse-epic avatar Jul 16 '25 23:07 slagesse-epic