-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Remove test flakiness #181
base: master
Are you sure you want to change the base?
Changes from all commits
3283a6b
5a24747
db8760a
a46d382
7c78ec1
e2ebcfa
fa7b741
334cac1
a529227
f5936a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,46 +10,46 @@ void main() { | |
final favoriteSong2 = songWith(id: 4, title: 'Song 4', isFavoriteInMediaStore: true); | ||
final favoriteSong3 = songWith(id: 5, title: 'Song 5', isFavoriteInMediaStore: true); | ||
|
||
setUp(() async { | ||
await setUpAppTest(() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this is a good API change that we not longer can use setUp between tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd argue it's not - it reduces the reusability of setup logic In some cases it might also make that tests utilities are not composable with each other - this is a real case in tests that I had recently, when I made a not very composable API desicion, which put constraints on how tests could be written, so I had to rewrite it at some point after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the description of the PR I see that you want them to live inside the same zone as other test logic It this possible to achieve in some other way? |
||
FakeSweyerPluginPlatform.instance.songs = [ | ||
notFavoriteSong1, | ||
notFavoriteSong2, | ||
notFavoriteSong3, | ||
favoriteSong1, | ||
favoriteSong2, | ||
favoriteSong3, | ||
]; | ||
}); | ||
Future<void> setupDefaultFavouriteState(TestWidgetsFlutterBinding binding) async { | ||
await Settings.useMediaStoreForFavoriteSongs.set(false); | ||
await Future.delayed(const Duration(seconds: 1)); // Wait for the listener in FavoriteControl to execute | ||
await binding.pump(const Duration(seconds: 1)); // Wait for the listener in FavoriteControl to execute | ||
await FakeFavoritesControl.instance | ||
.setFavorite(contentTuple: ContentTuple(songs: [favoriteSong1, favoriteSong2, favoriteSong3]), value: true); | ||
await FakeFavoritesControl.instance.setFavorite( | ||
contentTuple: ContentTuple(songs: [notFavoriteSong1, notFavoriteSong2, notFavoriteSong3]), value: false); | ||
}); | ||
} | ||
|
||
group('MediaStore', () { | ||
testWidgets('Updates the MediaStore correctly when resolving conflicts', (WidgetTester tester) async { | ||
final localFavoriteAndMediaStoreSong = favoriteSong1; | ||
final notFavoriteInBothSong = notFavoriteSong1; | ||
final localFavoriteButNotInMediaStoreKeepSong = notFavoriteSong2; | ||
final localFavoriteButNotInMediaStoreUnFavorSong = notFavoriteSong3; | ||
final mediaStoreFavoriteButNotLocalKeepSong = favoriteSong2; | ||
final mediaStoreFavoriteButNotLocalUnFavorSong = favoriteSong3; | ||
await FakeFavoritesControl.instance.setFavorite( | ||
contentTuple: ContentTuple( | ||
songs: [localFavoriteButNotInMediaStoreKeepSong, localFavoriteButNotInMediaStoreUnFavorSong], | ||
), | ||
value: true, | ||
); | ||
await FakeFavoritesControl.instance.setFavorite( | ||
contentTuple: ContentTuple( | ||
songs: [mediaStoreFavoriteButNotLocalKeepSong, mediaStoreFavoriteButNotLocalUnFavorSong], | ||
), | ||
value: false, | ||
); | ||
await tester.runAppTest(() async { | ||
await tester.runAppTest(initialization: () { | ||
FakeSweyerPluginPlatform.instance.songs = [ | ||
notFavoriteSong1, | ||
notFavoriteSong2, | ||
notFavoriteSong3, | ||
favoriteSong1, | ||
favoriteSong2, | ||
favoriteSong3, | ||
]; | ||
}, () async { | ||
await setupDefaultFavouriteState(tester.binding); | ||
final localFavoriteAndMediaStoreSong = favoriteSong1; | ||
final notFavoriteInBothSong = notFavoriteSong1; | ||
final localFavoriteButNotInMediaStoreKeepSong = notFavoriteSong2; | ||
final localFavoriteButNotInMediaStoreUnFavorSong = notFavoriteSong3; | ||
final mediaStoreFavoriteButNotLocalKeepSong = favoriteSong2; | ||
final mediaStoreFavoriteButNotLocalUnFavorSong = favoriteSong3; | ||
await FakeFavoritesControl.instance.setFavorite( | ||
contentTuple: ContentTuple( | ||
songs: [localFavoriteButNotInMediaStoreKeepSong, localFavoriteButNotInMediaStoreUnFavorSong], | ||
), | ||
value: true, | ||
); | ||
await FakeFavoritesControl.instance.setFavorite( | ||
contentTuple: ContentTuple( | ||
songs: [mediaStoreFavoriteButNotLocalKeepSong, mediaStoreFavoriteButNotLocalUnFavorSong], | ||
), | ||
value: false, | ||
); | ||
await Settings.useMediaStoreForFavoriteSongs.set(true); | ||
await tester.pumpAndSettle(); | ||
Finder findInDialog(Finder finder) => find.descendant(of: find.byType(AlertDialog), matching: finder); | ||
|
@@ -82,17 +82,37 @@ void main() { | |
|
||
testWidgets("When switching to MediaStore, doesn't show resolve conflict dialog with no conflicts", | ||
(WidgetTester tester) async { | ||
await tester.runAppTest(() async { | ||
await tester.runAppTest(initialization: () { | ||
FakeSweyerPluginPlatform.instance.songs = [ | ||
notFavoriteSong1, | ||
notFavoriteSong2, | ||
notFavoriteSong3, | ||
favoriteSong1, | ||
favoriteSong2, | ||
favoriteSong3, | ||
]; | ||
}, () async { | ||
await setupDefaultFavouriteState(tester.binding); | ||
await Settings.useMediaStoreForFavoriteSongs.set(true); | ||
await tester.pumpAndSettle(); | ||
expect(find.text(l10n.resolveConflict), findsNothing); | ||
}); | ||
}); | ||
|
||
testWidgets('Allows to cancel when resolving conflicts', (WidgetTester tester) async { | ||
await FakeFavoritesControl.instance | ||
.setFavorite(contentTuple: ContentTuple(songs: [notFavoriteSong1]), value: true); | ||
await tester.runAppTest(() async { | ||
await tester.runAppTest(initialization: () { | ||
FakeSweyerPluginPlatform.instance.songs = [ | ||
notFavoriteSong1, | ||
notFavoriteSong2, | ||
notFavoriteSong3, | ||
favoriteSong1, | ||
favoriteSong2, | ||
favoriteSong3, | ||
]; | ||
}, () async { | ||
await setupDefaultFavouriteState(tester.binding); | ||
await FakeFavoritesControl.instance | ||
.setFavorite(contentTuple: ContentTuple(songs: [notFavoriteSong1]), value: true); | ||
await Settings.useMediaStoreForFavoriteSongs.set(true); | ||
await tester.pumpAndSettle(); | ||
expect(find.text(l10n.resolveConflict), findsOneWidget); | ||
|
@@ -103,19 +123,32 @@ void main() { | |
}); | ||
}); | ||
|
||
testWidgets('Keeps favorites when switching form MediaStore to local', (WidgetTester tester) async { | ||
final favorSong = notFavoriteSong1; | ||
final unFavorSong = favoriteSong1; | ||
await Settings.useMediaStoreForFavoriteSongs.set(true); | ||
await tester.pumpAndSettle(); | ||
await FakeFavoritesControl.instance.setFavorite(contentTuple: ContentTuple(songs: [favorSong]), value: true); | ||
await FakeFavoritesControl.instance.setFavorite(contentTuple: ContentTuple(songs: [unFavorSong]), value: false); | ||
await Settings.useMediaStoreForFavoriteSongs.set(false); | ||
await tester.pumpAndSettle(); | ||
expect(FakeFavoritesControl.instance.isFavorite(unFavorSong), false); | ||
expect(FakeFavoritesControl.instance.isFavorite(notFavoriteSong2), false); | ||
expect(FakeFavoritesControl.instance.isFavorite(favorSong), true); | ||
expect(FakeFavoritesControl.instance.isFavorite(favoriteSong2), true); | ||
test('Keeps favorites when switching form MediaStore to local', () async { | ||
final binding = TestWidgetsFlutterBinding.ensureInitialized(); | ||
await binding.runAppTestWithoutUi(initialization: () { | ||
FakeSweyerPluginPlatform.instance.songs = [ | ||
notFavoriteSong1, | ||
notFavoriteSong2, | ||
notFavoriteSong3, | ||
favoriteSong1, | ||
favoriteSong2, | ||
favoriteSong3, | ||
]; | ||
}, () async { | ||
await setupDefaultFavouriteState(binding); | ||
final favorSong = notFavoriteSong1; | ||
final unFavorSong = favoriteSong1; | ||
await Settings.useMediaStoreForFavoriteSongs.set(true); | ||
await binding.pump(); | ||
await FakeFavoritesControl.instance.setFavorite(contentTuple: ContentTuple(songs: [favorSong]), value: true); | ||
await FakeFavoritesControl.instance.setFavorite(contentTuple: ContentTuple(songs: [unFavorSong]), value: false); | ||
await Settings.useMediaStoreForFavoriteSongs.set(false); | ||
await binding.pump(); | ||
expect(FakeFavoritesControl.instance.isFavorite(unFavorSong), false); | ||
expect(FakeFavoritesControl.instance.isFavorite(notFavoriteSong2), false); | ||
expect(FakeFavoritesControl.instance.isFavorite(favorSong), true); | ||
expect(FakeFavoritesControl.instance.isFavorite(favoriteSong2), true); | ||
}); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestengly, a side effect I see on many screenshots is that the shadow from the drawer seems to have gone
It's OK, just something I noticed reviewing golden changes