I have a utility class that relies on the context in order to translate the output. Something along the lines of : static String doSomeLogicAndTranslate(String firstArg, BuildContext context) { //... return AppLocalizations.of(context)!.someKey; } Now, I want to be able to write some unit tests for this class, but since the second argument is the context, I'm having a hard time doing so. What I have tried so far: Mocking a BuildContext with Mockito (as described here) and passing that as the second argument --> Doesn't work as inside the localizations.dart file it returns null here static T? of<T>(BuildContext context, Type type) { final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>(); /// Scope is null here return scope?.localizationsState.resourcesFor<T?>(type); } I have tried looking around for any other solutions for this, but have not found anything substantial. This seems like it should be pretty straight forward, but it isn't. Continue reading...