Skip to content

Instantly share code, notes, and snippets.

@Bharathh-Raj
Last active March 17, 2022 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bharathh-Raj/01931b3abe54f8ccf271e64fc69fbe22 to your computer and use it in GitHub Desktop.
Save Bharathh-Raj/01931b3abe54f8ccf271e64fc69fbe22 to your computer and use it in GitHub Desktop.
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'repository_test.mocks.dart'; // Don't forget to include this
@GenerateMocks([RemoteDateSource])
void main() {
test("fetch() should return an instance of student on remoteDataSource's fetch success", () {
//Arrange
MockRemoteDateSource mockDS = MockRemoteDateSource();
Repository repo = Repository(mockDS);
when(mockDS.fetch()).thenReturn("Mock Result");
//Act
final result = repo.fetch();
//Assert
expect(result, isInstanceOf<Student>());
});
test("fetch() should throw an exception on remoteDataSource's fetch throws any exception", () {
MockRemoteDateSource mockDS = MockRemoteDateSource();
Repository repo = Repository(mockDS);
when(mockDS.fetch()).thenThrow(SocketException("Mock exception"));
expect(() => repo.fetch(), throwsException);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment