tools icon indicating copy to clipboard operation
tools copied to clipboard

cover code for kIsWeb condition true and false both cases

Open kaushikbh99 opened this issue 2 years ago • 1 comments

In my case, I have developed apps for mobile and web both cases in one project, Now I write unit cases and set for code coverage, but in my case kIsWeb condition does not check both cases, e.g. if(kIsWeb){ // for web app }else{ // for non-web app }

so in this type of case not cover for web part, only covers for non-web app part My question is how can I cover both cases for unit testing?

kaushikbh99 avatar Jan 10 '24 04:01 kaushikbh99

@kaushikbh99 @mosuem You can cover both kIsWeb and non-web conditions by running your tests separately for each platform.

  1. For web coverage, run:
    flutter test --platform chrome
    

This ensures kIsWeb evaluates to true, covering the web-specific logic.

  1. For Non-web coverage, run:
    flutter test
    

This runs tests in a non-web environment (like Android/iOS), covering the else branch.

Victowolf avatar Mar 08 '25 05:03 Victowolf