testGame<T extends Game<Event> > function
- @isTest
- String testName, {
- required GameConfig config,
- required List<
Player> players, - required Future<
void> test(- GameTester<
T>
- GameTester<
Tests the game with T
type in a group with name
and test named name + '_Tests'
All parameters are required
config
specifies theGameConfig
players
specifies the list of playerstest
gives you access to a GameTester which allows you to test the game
Uses the OnDevice clients TODO: Maybe try to use only Backend Providers as long as nothing need to be async (which it shouldn't since the game method are all non-async)?
Implementation
@isTest
void testGame<T extends Game>(
String testName, {
required GameConfig config,
required List<Player> players,
required Future<void> Function(GameTester<T>) test,
}) {
darttest.test(testName, () async {
final root = ProviderContainer();
final readers = <PlayerID, Reader>{};
root.read(GameProviders.clientType.notifier).state = OnDeviceClient;
for (final p in players) {
readers[p.id] = ProviderContainer(
parent: root,
overrides: [GameProviders.playerID.overrideWithValue(p.id)]).read;
}
readers[players.first.id]!(GameProviders.config.notifier).state = config;
final code =
await readers[players.first.id]!(GameProviders.createGame.future);
for (final p in players) {
readers[p.id]!(GameProviders.code.notifier).state = code;
await readers[p.id]!(GameProviders.joinGame.future);
}
if (readers[players.first.id]!(GameProviders.status) !=
GameStatus.Started) {
await readers[players.first.id]!(GameProviders.startGame.future);
}
await test(GameTester<T>(root.read, readers, players, code));
});
}