-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from dherediat97/feature/unit-test
Feature/unit test
- Loading branch information
Showing
16 changed files
with
1,022 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#!/bin/bash | ||
# Generate `coverage/lcov.info` file | ||
flutter test --coverage | ||
# Generate HTML report | ||
genhtml coverage/lcov.info -o coverage/html | ||
/c/ProgramData/chocolatey/lib/lcov/tools/bin/genhtml coverage/lcov.info -o coverage/html | ||
# Open the report | ||
open coverage/html/index.html | ||
start coverage/html/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:film_flu/domain/models/media_data_entity.dart'; | ||
import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:test/scaffolding.dart'; | ||
|
||
import 'home_bloc_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks([MockSpec<MediaListBloc>()]) | ||
void main() { | ||
late MockMediaListBloc mockBlock; | ||
|
||
setUp( | ||
() { | ||
mockBlock = MockMediaListBloc(); | ||
}, | ||
); | ||
|
||
group( | ||
'Testing Home Screen Bloc', | ||
() { | ||
blocTest( | ||
'Given Home Screen Bloc when load the bloc then return the empty expected result', | ||
build: () => mockBlock, | ||
expect: () => [], | ||
); | ||
|
||
blocTest( | ||
'Given HomeScreenBloc when load the bloc then return the expected result', | ||
build: () => mockBlock, | ||
act: (bloc) => bloc.add(const MediaListEvent.getMediaData()), | ||
expect: () => [ | ||
MediaListState.initial().copyWith( | ||
mediaData: const MediaDataEntity( | ||
fictionMovies: [], | ||
dramasMovies: [], | ||
actionMovies: [], | ||
romanceMovies: [], | ||
comedyMovies: [], | ||
suspenseMovies: [], | ||
animeSeries: [], | ||
animationSeries: [], | ||
tvShowsSeries: [], | ||
documentalSeries: [], | ||
), | ||
mediaList: List.empty(), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// Mocks generated by Mockito 5.4.4 from annotations | ||
// in film_flu/test/features/home/bloc/home_bloc_test.dart. | ||
// Do not manually edit this file. | ||
|
||
// ignore_for_file: no_leading_underscores_for_library_prefixes | ||
import 'dart:async' as _i3; | ||
|
||
import 'package:film_flu/presentation/features/media_list/bloc/media_list_bloc.dart' | ||
as _i2; | ||
import 'package:flutter_bloc/flutter_bloc.dart' as _i4; | ||
import 'package:mockito/mockito.dart' as _i1; | ||
|
||
// ignore_for_file: type=lint | ||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: deprecated_member_use | ||
// ignore_for_file: deprecated_member_use_from_same_package | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
// ignore_for_file: camel_case_types | ||
// ignore_for_file: subtype_of_sealed_class | ||
|
||
class _FakeMediaListState_0 extends _i1.SmartFake | ||
implements _i2.MediaListState { | ||
_FakeMediaListState_0( | ||
Object parent, | ||
Invocation parentInvocation, | ||
) : super( | ||
parent, | ||
parentInvocation, | ||
); | ||
} | ||
|
||
/// A class which mocks [MediaListBloc]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockMediaListBloc extends _i1.Mock implements _i2.MediaListBloc { | ||
@override | ||
_i2.MediaListState get state => (super.noSuchMethod( | ||
Invocation.getter(#state), | ||
returnValue: _FakeMediaListState_0( | ||
this, | ||
Invocation.getter(#state), | ||
), | ||
returnValueForMissingStub: _FakeMediaListState_0( | ||
this, | ||
Invocation.getter(#state), | ||
), | ||
) as _i2.MediaListState); | ||
|
||
@override | ||
_i3.Stream<_i2.MediaListState> get stream => (super.noSuchMethod( | ||
Invocation.getter(#stream), | ||
returnValue: _i3.Stream<_i2.MediaListState>.empty(), | ||
returnValueForMissingStub: _i3.Stream<_i2.MediaListState>.empty(), | ||
) as _i3.Stream<_i2.MediaListState>); | ||
|
||
@override | ||
bool get isClosed => (super.noSuchMethod( | ||
Invocation.getter(#isClosed), | ||
returnValue: false, | ||
returnValueForMissingStub: false, | ||
) as bool); | ||
|
||
@override | ||
void add(_i2.MediaListEvent? event) => super.noSuchMethod( | ||
Invocation.method( | ||
#add, | ||
[event], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void onEvent(_i2.MediaListEvent? event) => super.noSuchMethod( | ||
Invocation.method( | ||
#onEvent, | ||
[event], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void emit(_i2.MediaListState? state) => super.noSuchMethod( | ||
Invocation.method( | ||
#emit, | ||
[state], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void on<E extends _i2.MediaListEvent>( | ||
_i4.EventHandler<E, _i2.MediaListState>? handler, { | ||
_i4.EventTransformer<E>? transformer, | ||
}) => | ||
super.noSuchMethod( | ||
Invocation.method( | ||
#on, | ||
[handler], | ||
{#transformer: transformer}, | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void onTransition( | ||
_i4.Transition<_i2.MediaListEvent, _i2.MediaListState>? transition) => | ||
super.noSuchMethod( | ||
Invocation.method( | ||
#onTransition, | ||
[transition], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
_i3.Future<void> close() => (super.noSuchMethod( | ||
Invocation.method( | ||
#close, | ||
[], | ||
), | ||
returnValue: _i3.Future<void>.value(), | ||
returnValueForMissingStub: _i3.Future<void>.value(), | ||
) as _i3.Future<void>); | ||
|
||
@override | ||
void onChange(_i4.Change<_i2.MediaListState>? change) => super.noSuchMethod( | ||
Invocation.method( | ||
#onChange, | ||
[change], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void addError( | ||
Object? error, [ | ||
StackTrace? stackTrace, | ||
]) => | ||
super.noSuchMethod( | ||
Invocation.method( | ||
#addError, | ||
[ | ||
error, | ||
stackTrace, | ||
], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
|
||
@override | ||
void onError( | ||
Object? error, | ||
StackTrace? stackTrace, | ||
) => | ||
super.noSuchMethod( | ||
Invocation.method( | ||
#onError, | ||
[ | ||
error, | ||
stackTrace, | ||
], | ||
), | ||
returnValueForMissingStub: null, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:film_flu/presentation/features/home/home_screen.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../../../instruments/pump_app.dart'; | ||
|
||
void main() { | ||
testWidgets('Testing Home Screen', (WidgetTester tester) async { | ||
await pumpApp( | ||
tester, | ||
const HomeScreen(), | ||
); | ||
}); | ||
} |
56 changes: 56 additions & 0 deletions
56
test/features/media_detail/bloc/media_detail_bloc_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:bloc_test/bloc_test.dart'; | ||
import 'package:film_flu/app/types/ui_state.dart'; | ||
import 'package:film_flu/presentation/features/media_details/bloc/media_detail_bloc.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
|
||
import 'media_detail_bloc_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks([MockSpec<MediaDetailBloc>()]) | ||
void main() { | ||
late MockMediaDetailBloc mockBlock; | ||
|
||
setUp( | ||
() { | ||
mockBlock = MockMediaDetailBloc(); | ||
}, | ||
); | ||
|
||
group( | ||
'Testing Media Detail Screen Bloc', | ||
() { | ||
blocTest( | ||
'Given MediaDetailBloc when load the bloc then return the empty expected result', | ||
build: () => mockBlock, | ||
expect: () => [], | ||
); | ||
|
||
blocTest( | ||
'Given MediaDetailBloc when load the bloc then return the expected result', | ||
build: () => mockBlock, | ||
act: (bloc) => | ||
bloc.add(const MediaDetailEvent.getMediaDetails('movie', '11111')), | ||
expect: () => [ | ||
MediaDetailState.initial().copyWith( | ||
credits: null, | ||
isCastSelected: true, | ||
isTrailerOpened: false, | ||
mediaItem: null, | ||
movieName: '', | ||
trailerId: '', | ||
uiState: const UiState.loading(), | ||
), | ||
MediaDetailState.initial().copyWith( | ||
credits: null, | ||
isCastSelected: true, | ||
isTrailerOpened: false, | ||
mediaItem: null, | ||
movieName: '', | ||
trailerId: '', | ||
uiState: const UiState.success(), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} |
Oops, something went wrong.