Search code examples
unit-testingtestingflutterdartflutter-test

How can I test DART's runApp() function


I can't reach 100% test coverage because of DART's runApp() function. I tried to create tests for this function, but couldn't. Has anyone created a test for this function?

void main() => runApp(MyApp());

My coverage is 96.2% because only one line with the runApp() function has no test.

I would like to know how to create a unit test for this function.

enter image description here

Project source: full_testing_flutter


Solution

  • You can use comments to tell the coverage calculator to ignore lines:

    // coverage:ignore-start
    void main() => runApp(MyApp());
    // coverage:ignore-end
    
    

    I wouldn't recommend letting this strategy permeate the rest of your code, but for this simple one-off, it seems fine.