test_helper 1.3.1 copy "test_helper: ^1.3.1" to clipboard
test_helper: ^1.3.1 copied to clipboard

Helper methods for testing (comparing lists, testing a "theory", ...) and common mocks.

example/test_helper_example.dart

import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'package:test_helper/test_helper.dart';

void main() {
  test("theory example: calculates squared correctly", () {
    const inlineData = [-1, 0, 1, 2, 10];
    theory<int>(inlineData, (number) {
      final someMock =
          MockClass(); // use correct mocking library to create mock object ("mockito" is my favourite ;))
      final someClassUsingMock = ClassUsingMock(someMock);
      someClassUsingMock.doSomething();
      verify(someMock.doSomething());
    });
  });

  test("theory results example: some class forwards to mock class", () {
    const inlineData = [-1, 0, 1, 2, 10];
    const expected = [1, 0, 1, 4, 100];
    theoryResult<int, int>(
        inlineData, expected, (number) => Calculator().squared(number));
  });
}

class MockClass {
  void doSomething() {}
}

class ClassUsingMock {
  final MockClass someMock;

  ClassUsingMock(this.someMock);

  void doSomething() {
    someMock.doSomething();
  }
}

class Calculator {
  int squared(int num) => num * num;
}
1
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Helper methods for testing (comparing lists, testing a "theory", ...) and common mocks.

License

MIT (LICENSE)

Dependencies

collection, firebase_auth_helper, mockito, resource_result, test

More

Packages that depend on test_helper