stash_test

A stash test support package

Pub Package Coverage Status Package Documentation GitHub License

Overview

Provides testing support stash storage and cache implementations

Getting Started

Add this to your pubspec.yaml (or create it) on the dev_dependencies section replacing x.x.x with the latest version of stash_test:

dev_dependencies:
    stash_test: ^x.x.x

Run the following command to install dependencies:

dart pub get

Finally, to start developing import the library:

import 'package:stash_test/stash_test.dart';

Usage

The stash_test library provides a way to easily import the set of standard tests for Store and Cache allowing to reuse them to test custom implementations provided by external parties but also to test the storage and cache implementations provided in the package ecossistem of stash. The main objective is to guarantee that all storage implementations perform the full suite of type tests but also the standart stash tests.

For example let's consider that a third party developer creates a custom store, CustomStore, and wishes to test it against the same set of tests that are used on stash_file, stash_hive and similar packages. On the test/custom folder of the package the following file custom_store_test.dart can be created:

import 'package:stash_custom/stash_custom.dart';
import 'package:stash_test/stash_test.dart';

class DefaultContext extends TestContext<CustomStore> {
  DefaultContext(ValueGenerator generator,
      {dynamic Function(Map<String, dynamic>)? fromEncodable})
      : super(generator, fromEncodable: generator.fromEncodable);

  @override
  Future<FileStore> newStore() {
    return Future.value(CustomStore(..., fromEncodable: fromEncodable));
  }
}

void main() async {
  testStore((generator) => DefaultContext(generator));
  testCache((generator) => DefaultContext(generator));
}

Notice that in order to leverage the same set of tests a class extending TextContext needs to created and used on the calls to the two provided functions:

  • testStore: which runs all the store tests
  • testCache: which runs all the cache tests

Please take a look at the examples provided on one of the storage implementations, for example stash_file or stash_sqlite.

Features and Bugs

Please file feature requests and bugs at the issue tracker.

License

This project is licensed under the MIT License - see the LICENSE file for details

Libraries

stash_test
Provides testing support to third party extensions