Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Increase test coverage #128

Closed
aagarwal1012 opened this issue Oct 22, 2020 · 11 comments
Closed

[feat] Increase test coverage #128

aagarwal1012 opened this issue Oct 22, 2020 · 11 comments
Labels
enhancement New feature or request testing

Comments

@aagarwal1012
Copy link
Owner

Current Codecov test coverage is 69%, our goal is to increase this coverage to more than 90%. We can take reference from flutter_spinkit tests -- https://github.com/jogboms/flutter_spinkit/tree/master/test.

@aagarwal1012 aagarwal1012 added enhancement New feature or request testing labels Oct 22, 2020
@aagarwal1012
Copy link
Owner Author

@awhitford @SirusCodes @hemilpanchiwala any suggestion on this one?

@SirusCodes
Copy link
Collaborator

TBH I'm not really good in testing 😅 but I would try to look into it and add something to the repo👍

@awhitford
Copy link
Collaborator

This is a good question. I started poking around and ended up submitting a couple of pull requests because I found unused code and other opportunities for improvement. However, this lead me to be suspicious of the code coverage statistic.

This report, from one of my changes, is a great example. It computes a decrease of code coverage by 10%, but practically every line is covered. The uncovered/red lines are for constructor assertions. I'm wondering if this is a bug or a configuration issue because those lines should have been covered.

Beyond this statistic quality question, I noticed that some code is not being covered for various operations like onTap or onFinished.

@awhitford
Copy link
Collaborator

I recorded an issue on CodeCov's Community Support:

@awhitford
Copy link
Collaborator

From SpinKit, it looks like maybe verifyTickersWereDisposed should be called to validate dispose/cleanup.

And likely using pumpAndSettle with a duration will be necessary to allow the animations to completely finish. I like the idea of running widgets twice -- once that doesn't let the animation finish, and again when it does. This will test real-world interruptions and ensure that code cancels and cleans up correctly.

@awhitford
Copy link
Collaborator

I experimented with changing Smoke Test to be something like this:

  testWidgets('Check button smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(MyApp());

    for (var label in labels) {
      print('Testing $label');
      await tester.idle();
      expect(find.text(label), findsOneWidget);
      await tester.idle();
      await tester.pump();
      final pumpCount = await tester.pumpAndSettle();
      print(' > $label pumped $pumpCount');

      await tester.tap(find.byIcon(Icons.play_circle_filled));
      await tester.pump();
    }

    tester.verifyTickersWereDisposed();
  }

I think the pumpAndSettle helps exercise the animations. However, animations can't be forever/repeating. I am stuck trying to get past TextLiquidFill:

00:02 +0: Check button smoke test                                                                                                          
Testing Rotate
 > Rotate pumped 21
Testing Fade
 > Fade pumped 21
Testing Typer
 > Typer pumped 14
Testing Typewriter
 > Typewriter pumped 9
Testing Scale
 > Scale pumped 21
Testing Colorize
 > Colorize pumped 21
Testing TextLiquidFill
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
pumpAndSettle timed out

When the exception was thrown, this was the stack:
#0      WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart:688:11)
<asynchronous suspension>
#1      WidgetTester.pumpAndSettle.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
#4      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#5      WidgetTester.pumpAndSettle (package:flutter_test/src/widget_tester.dart:683:27)
#6      main.<anonymous closure> (file:///Users/anthony/github/awhitford/Animated-Text-Kit/test/smoke_test.dart:16:38)
<asynchronous suspension>
#7      main.<anonymous closure> (file:///Users/anthony/github/awhitford/Animated-Text-Kit/test/smoke_test.dart)

As far as I can tell, TextLiquidFill is not infinite, so I'm puzzled as to why pumpAndSettle timed out.

@awhitford
Copy link
Collaborator

🤓 So TextLiquidFill is infinite because _waveController is repeating. And I think that is on purpose to get the wavy water effect. It seems that the failing test was indicating a bug. 🐛

@awhitford
Copy link
Collaborator

There are a couple of tweaks (like PR #133), but basically changing smoke_test to this:

  testWidgets('Check button smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(MyApp());

    // Exercise each Animation...
    for (var label in labels) {
      print('Testing $label');
      expect(find.text(label), findsOneWidget);
      final pumpCount = await tester.pumpAndSettle();
      print(' > $label pumped $pumpCount');

      await tester.tap(find.byIcon(Icons.play_circle_filled));
      await tester.pump();
    }

    tester.verifyTickersWereDisposed();
  });

will raise test coverage by 10.6%.

Before:
image
After:
image

Wavy in particular looks great.

Another opportunity is to add unit tests to exercise the Tap & Pause functionality that some animations offer.

@aagarwal1012
Copy link
Owner Author

A lot of comments for the follow-up but I think most of the @awhitford 's comments self answers themselves. Great investigation, waiting for your Pull Request.

@awhitford
Copy link
Collaborator

PR #135 makes the above mentioned change. Note that this new test code actually highlighted a couple of bugs that were fixed by #133:

  • TextLiquidFill's wave was repeating endlessly -- now that is fixed -- not sure if this was draining the battery
  • Colorized has a timer that was not being properly canceled -- now that is fixed, just like the other classes

@aagarwal1012
Copy link
Owner Author

#157 closes this issue. Thanks, @awhitford 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing
Projects
None yet
Development

No branches or pull requests

3 participants