Ignoring via comments does not work all the time with code coverage
I use
// coverage:ignore-start
void doNotCheckForCoverage()
{
someCode();
}
// coverage:ignore-end
everywhere and it used to work good. But after writing a lot of test a strange behaviour occured. Sometimes it does not work as intedent and I think its a bug.
As u can see below it does not work in this file:

But it is working in other places in the same project under the same test dir all ending with the _test.dart postfix, like here:

Command used to execute the tests are
flutter test --coverage
Are you running with --enable-asserts? If not, I would expect 0 hits for any of those lines. Or do you mean you're expecting the lines to have a blank hit-count and not zero?
@liamappelbe how is coverage tracked for assertions?
My assumption would be that:
- If a line is executable, the VM would track hits and the coverage package, we should emit a hit-count. In this case if running with
--enable-asserts, I'd expect a hit-count >= 0. - If a line is not executable, the VM would ignore those spans altogether and the coverage package, we should therefore not emit a hit-count; so if running without
--enable-asserts, I'd expect no hit-count.
If a line is executable and ignored, I'd expect the VM would collect the hit count and the coverage package should suppress the hit-count for that line -- i.e. shows blank rather than 0. @grouma is that the current behaviour?
I expect them to have a blank hit count and not zero like in the second image.
Im running without --enable-asserts. It was said that asserts like assert(someVar != null) cannot be covered by coverage but i might be wrong here. The solution for this problem was for me to wrap everything into the // coverage:ignore-... stuff in order to ignore the asserts.
If --enable-asserts would fix my entire problem im totally fine with it, still its kinda wierd that some of the ignore stuff is working as intended and some not, defenitly something to look at.
Just one question, how can you --enable-asserts using the flutter test command? it seems like impossible to me.
Edit: Oh I realized its not possible.
Just one question, how can you --enable-asserts using the flutter test command? it seems like impossible to me.
flutter test uses the flutter_tester binary, which enables asserts by default. You can disable them with the --disable-dart-asserts option. I'm not 100% sure whether or not the flutter tool exposes that option, but if it doesn't you could file a feature request in the flutter/flutter repo.
If a line is executable and ignored, I'd expect the VM would collect the hit count and the coverage package should suppress the hit-count for that line -- i.e. shows blank rather than 0. @grouma is that the current behaviour?
That should be the current behavior. If the line is ignored it is not added to the global hitmap. It's possible we aren't parsing the set of ignored lines correctly but that's difficult to determine without a repro.
@iOSonntag try positioning the comment after the line (example) it worked for me