-
Notifications
You must be signed in to change notification settings - Fork 109
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
Unit tests for root files #389
base: main
Are you sure you want to change the base?
Conversation
@rohansen856 Make sure it passes all the checks. |
Thanks for the follow up @BrawlerXull . Currently there seems to be some changes in package |
@BrawlerXull I have updated the test and it's currently passing 100% tests. For going further, I would like your advice on should i open different PRs for different folders in the codebase (as some folder contents are quite large), or should i do all the tets in this PR alone (folder by folder). thank you. |
@Pavel401 @BrawlerXull any suggestion? |
Sorry for late reply was busy in some work. |
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.
Also make sure u add relevant testcases removing testcases to make flutter test is not the solution please add testcases like fetchTasks returns list of Tasks on success
and make sure it works.
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.
Definitely @BrawlerXull . There has been some problems with the mock fetchtasks
due to its dependence taskchampion server. I will resolve the issue and add the test shortly. Thanks.
Is there any update on this? @rohansen856 @BrawlerXull |
Extremely Sorry for the late, I will update the tests and try to make PR within a day. thanks! |
@Pavel401 I see that due to current changes in the codebase, there are also some other tests that are failing... I would solve all of them and make a PR so that all tests are up to date and passing. |
@Pavel401 While rewriting tests for the Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
var response = await http.get(Uri.parse(url), headers: {
"Content-Type": "application/json",
}).timeout(const Duration(seconds: 10000));
if (response.statusCode == 200) {
List<dynamic> allTasks = jsonDecode(response.body);
debugPrint(allTasks.toString());
return allTasks.map((task) => Tasks.fromJson(task)).toList();
} else {
throw Exception('Failed to load tasks');
}
} throws direct exceptions, which should not happen. I would suggest to encapsulate it inside a try catch block or handle it in other way. ex.: Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
try {
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';
var response = await http.get(Uri.parse(url), headers: {
"Content-Type": "application/json",
}).timeout(const Duration(seconds: 10000));
if (response.statusCode == 200) {
List<dynamic> allTasks = jsonDecode(response.body);
debugPrint(allTasks.toString());
return allTasks.map((task) => Tasks.fromJson(task)).toList();
} else {
throw Exception('Failed to load tasks');
}
} catch (e) {
debugPrint('Failed to add tasks: $e');
return [];
}
} any thought about this...? |
@Pavel401 @BrawlerXull it seems that the |
Description
Please include a summary of the change and which issue is fixed. List any dependencies that are required for this change.
Fixes #388
Summary:
http_mock_adapter
andsqflite_common_ffi
for mocking local server and databaselib/main
andlib/api_service.dart
test result:
NULL safety
error issue. please follow this thread for any confusion: stackoverflow. added this line for resolving it:@GenerateMocks([MockMethodChannel])
String baseUrl = 'http://YOUR_IP:8000';
,String origin = 'http://localhost:8080';
mocking with server up:
00:10 +54: /home/rcsen/Documents/open-source/taskwarrior_test/test/api_service_test.dart: TaskDatabase insertTask adds a task to the database Deleted all tasks Created new task table 00:10 +55: /home/rcsen/Documents/open-source/taskwarrior_test/test/api_service_test.dart: TaskDatabase deleteAllTasksInDB removes all tasks Deleted all tasks Created new task table Deleted all tasks Created new task table 00:10 +56: All tests passed!
mocking with server down:
Checklist