Does Code Coverage support DART 2 for Flutter projects? - flutter

On the Official Flutter Packages website, it is written that the plugin for Code Coverage, dart_codecov_generator (https://pub.dev/packages/dart_codecov_generator), is DART 2 INCOMPATIBLE. So, is there a way we can use Code Coverage for Flutter projects?

Yes it possible to get the code coverage for a flutter project.
if you run flutter test --coverage, it will output a file (lcov.info) in the coverage folder and then multiple solution are possible:
you can use genhtml program on this file to get the coverage (you will have to do some parsing)
use online tool like codecov to upload you code coverage into the service.

Related

How do I run a command line tool that depends on Flutter?

The flutter_test package is able to run Flutter apps 'headless', without requiring any embedder. It would be useful to me to be able to run a command line tool (i.e. not a test) in the same mode. Is this possible? I looked at the flutter_test package but nothing there seems to be the magic solution.
What I've tried:
Running a CLI tool that depends on Flutter with dart path/to/tool.dart. This throws Error: Not found: 'dart:ui'.
Running it with flutter run path/to/tool.dart. This will attempt to start the CLI tool as a regular Flutter app on a device (such as an Emulator, the desktop OS, or a web browser).
Running with flutter pub run path/to/tool.dart just generates a lot of errors, such as "Error: 'Paint' isn't a type". I tried all approaches suggested in this related SO Question, with the script living in various directories and using different invocations, but no luck.
Running the tool using flutter test path/to/tool.dart does work, and it runs the code in main() like one would expect. But I consider this a hacky workaround, since flutter test (unsurprisingly) expects a test, and exits with the error "No tests were found." And, semantically, it's just wrong. This is not a test. It's a tool.
If your code relies on package:flutter or dart:ui, you won't be able to run it outside of a Flutter engine instance (e.g., flutter_tester or a Flutter application) as dart:ui is a custom core library for Flutter that isn't part of Dart's core libraries. Short of hacking away at flutter_tester to remove the test runner related logic or creating your own custom embedder of the Flutter engine, you won't be able to run a Flutter project headless on the command line.
Ideally, you'd just refactor your tool to not depend on dart:ui at all, but given your background I'm guessing you're trying to do something non-standard that actually requires functionality from the Flutter framework... :-)

How can we generate HTML Report of Integration Test in Flutter Automation Testing

How can we generate HTML Report of Integration Test in Flutter Automation Testing.
Being an Automation Tester, I've been working on an existing Flutter Automation Project which is running as Integration Test. Like Selenium I also want to generate HTML report of whatever .dart file or testscript being executed.
Hope we get some solid solutions for the same.
Once you could generate the coverage report in lcov.info ( line coverage).
Then you can create the web report as :
Generate HTML report.
Note: on macOS you need to have lcov installed on your system (brew install lcov) to use this:
genhtml coverage/lcov.info -o coverage/html
Open the report
open coverage/html/index.html

Flutter code coverage reports in VS Code on Windows?

Does anyone know a good way to see generated code coverage reports for a Flutter project in Windows, preferably using VS Code? I know I can generate coverage reports using flutter test --coverage which generates a coverage file (coverage\lcov.info).
But how can I use this in VS Code? I found an extension called Coverage Gutters that I can use to visualize covered lines with a green color. It's not perfect for dart/flutter code but it works OK. An example is that it does not mark green lines for line separated arguments to a method or constructor even if those arguments are included in tests.
But the main problem is that I can't get any visual report of the coverage. There are tools (primarily genhtml) that are used to generate HTML reports from the lcov.info but this does not seem to be available on Windows. Do I need to install the Linux subsystem for Windows 10 and install genhtml that way?
Please let me know if you have tips on how to use code coverage for Flutter in Windows (reports and/or line visualization in VS Code). Thanks!
A way--I wouldn't call it a good way, but at least it's easy and it works--is to install Atom text editor and the Dart and lcov-info packages. Then open your Flutter project and click Ctrl+Alt+c and the coverage report in graphical format will be displayed.

How to enable the code coverage view on VSTS?

My team uses VSTS with hosted agents and a Visual Studio Test build task to run all tests and produce code coverage. However the tab Code coverage remains empty afterwards, only showing a link to download the *.coverage file.
I actually expect the code coverage results to be shown, with tables and graphs which projects are tested and it's respective coverage.
We are using the Visual Studio Test build task to test net461 assemblies with the Code Coverage enabled checked.
Somewhat related are both this and this issue, but not entirely, because we are just using MSTest Framework with built-in Visual Studio Test build task, which (I understand) should also automatically publish the code coverage results.
Am I missing something to get this Code coverage view working? Thanks!!
In Code coverage Tab, you need to use Publish Code Coverage Results task to show tables and graphs there.
While for Publish Code Coverage Results task, it only supports Code Coverage data in Jacoco or Cobertura formats. So the result of the *.coverage file can not be shown by tables and graphs in Code coverage Tab.
More details, you can refer the blog Browse Code Coverage reports and the issue How to publish the code coverage result with a .coverage file.

gcovr - cobertura

With gcovr I am able to generate code coverge report(coverage.xml) for my IOS application.How will I use cobertura plugin to convert the coverage.xml to cobertura html report?
Any help appreciated!
I use the lcov tool suite to generate HTML reports like these. . . The build-script to do this is here.
Nice feature: After every build from the build server, the results are uploaded to the Github page.
I was thinking of making a tool to auto-install the script in Xcode. There's an app you can use to view coverage results, but I was after something that:
Can be run from cmd-line. This makes it compatible with CI build-servers as well as easy to verify results locally.
lcov can easily be installed via MacPorts or home-brew.