Created
March 17, 2022 07:31
-
-
Save Bharathh-Raj/4f26445e2ea0c31f95d87a8e9af01275 to your computer and use it in GitHub Desktop.
MockTail
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
class MockRemoteDataSource extends Mock implements 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