mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-07-15 02:46:03 +08:00
Example for Unit Test (#52)
This commit is contained in:
58
unit_testing/test/unit/formValidator_test.dart
Normal file
58
unit_testing/test/unit/formValidator_test.dart
Normal file
@ -0,0 +1,58 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:unit_testing/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group(
|
||||
'Email test',
|
||||
() {
|
||||
test(
|
||||
'Valid Email test',
|
||||
() {
|
||||
final result = FormValidator.validateEmail("example@flutter.com");
|
||||
expect(result, isNull);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'Invalid Email test',
|
||||
() {
|
||||
final result = FormValidator.validateEmail("abcf");
|
||||
expect(result, 'please enter valid email');
|
||||
},
|
||||
);
|
||||
test(
|
||||
'Empty email test',
|
||||
() {
|
||||
final result = FormValidator.validateEmail("");
|
||||
expect(result, 'please enter email');
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
group(
|
||||
'Password Test',
|
||||
() {
|
||||
test(
|
||||
'Empty password test',
|
||||
() {
|
||||
final resutl = FormValidator.validatePassword("");
|
||||
expect(resutl, 'please enter your password');
|
||||
},
|
||||
);
|
||||
test(
|
||||
'Valid password test',
|
||||
() {
|
||||
final resutl = FormValidator.validatePassword("hello@123456");
|
||||
expect(resutl, isNull);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'Invalid password test',
|
||||
() {
|
||||
final resutl = FormValidator.validatePassword("hello");
|
||||
expect(resutl, 'minimum lenght of password must be 8 characters');
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user