Skip to content

Instantly share code, notes, and snippets.

@enzodanjour
Last active April 29, 2021 01:50
Show Gist options
  • Select an option

  • Save enzodanjour/02d1f7b25abe95c0ed9e09dfceed2bc8 to your computer and use it in GitHub Desktop.

Select an option

Save enzodanjour/02d1f7b25abe95c0ed9e09dfceed2bc8 to your computer and use it in GitHub Desktop.
Flutter unit test example
import 'package:flutter_test/flutter_test.dart';
main() {
//Arrange
//inicialização do código
HomeController controller;
setUp(() {
controller = HomeController();
});
// group a conjunct of tests
group("Home Controller tests", () {
test("Post initial value is null", () {
//Assert, observação
expect(controller.posts.value, isNull);
//se as condições corresponderem, o teste foi aprovado
//if condictions match, the test has been passed.
});
test("Initial Posts size it's ok", () {
//Act, execução
await controller.getPosts();
final posts = controller.posts.value;
//Assert, observação
expect(posts.length, 3);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment