I have a method in a Dart class, which accepts BuildContext
parameter, as follows:
class MyClass {
<return_type> myMethodName(BuildContext context, ...) {
...
doSomething
return something;
}
}
I want to test that the method works as expected:
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
...
void main() {
MyClass sut;
setUp(() {
sut = MyClass();
});
test('me testing', () {
var actual = sut.myMethodName(...);
expect(actual, something);
});
}
Of course, it won't work, because the method myMethodName
needs a parameter BuildContext
type. This value is available throughout the application itself, but not sure where to get that from in my unit tests.