activatory 0.0.20

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

Activatory #

Build Status Coverage Status Pub

This project is aimed to bring a test data generator to Dart's ecosystem. This will greatly simplify unit testing and especially Test-Driven Development.

This project is inspired by .NET Autofixture library.

Supported features #

  • Effortless primitive types (String, int, double, bool, DateTime, enums) generating.
  • Effortless complex object generating using constructors/factory methods/named constructors (default values usage is customizable).
  • Overriding default generating behavior with custom factories, pinned values defined by user or auto generated.
  • Overriding default generating behavior for specific cases using any object as a key.
  • Lists (and Iterables) generating with customizable size: it is effortless for primitive types and require explicit registration for enums and complex types.
  • Maps of customizable size generating with explicit registration.
  • Support of recursive graphs (trees, linked lists and etc) with customizable recursion level.
  • Generic class instances generating with explicit factory registration.
  • Customization of ctor resolution: first defined, random, random named, random default.
  • Overriding generated parameters values by type and name for cases when random values are not applicable.
  • Creating aliases for inheritor classes

Roadmap #

This is my first Dart project and, actually, this is "pet-project". So there are no exact plans and etc. For planned features and more see enhancements on github.

v0.0.1-0.0.4 #

  • Added support for primitive objects activation: int, double, String, bool, DateTime
  • Added support for complex object activation by calling ctors, named ctors, factories and using positional arguments

v0.0.5 #

  • Named arguments supported
  • Complex object activation now respects default non null values

v0.0.6 #

  • Added ability to register factory explicitly

v0.0.7 #

  • Added ability to register generated singleton
  • Added ability to register pre defined value

v0.0.8 #

  • Back-ends now can be registered and lookuped using any object as a key
  • useSingleton renamed to pin, useValue renamed to pinValue

v0.0.9 #

  • Added effortless support for primitive types arrays generating (except of enums arrays)
  • Added support for complex types array generating with explicit array registration
  • Fixed enum generation bug (generated values was not real enum values from values list)

v0.0.10 #

  • Added custom exception type for all library internal errors

v0.0.11 #

  • Added recursion handling
  • Performed large refactoring

v0.0.12 #

  • Added test for generics support with explicit overriding
  • Added parameterizable custom factories support

v0.0.13 #

  • Added ctor resolution customization mechanism

v0.0.14 #

  • Fixed wrong counting of types in recursion limiter
  • Added customization mechanism for recursion limiter and array backend
  • Added Null type support

v0.0.15 #

  • Const ctor supported

v0.0.16 #

  • Bugfix and documentation improvements
  • Added support for Map<K,V> generating

v0.0.17 #

  • Implemented ctor parameter overloading by type and (optionally) by name

v0.0.18 #

  • Added getMany and getManyTyped for effortless array creation
  • Added type aliases support

v0.0.19 #

  • Added default argument values usage customization
  • Added per key customization

v0.0.20 #

  • Added fields and setter values activation
  • Added customization for fields and setters activation

example/activatory_example.dart

import 'package:activatory/src/activatory.dart';

main() {
  var activatory = new Activatory();

  // We can create primitive types
  print('Int: ${activatory.getTyped<int>()}');
  print('String: ${activatory.getTyped<String>()}');
  print('DateTime: ${activatory.getTyped<DateTime>()}');
  print('Bool: ${activatory.getTyped<bool>()}');
  print('TestEnum: ${activatory.getTyped<TestEnum>()}');

  //We can create complex types
  var complexClassInstance = activatory.getTyped<SomeComplexClass>();
  print('Complex.String: ${complexClassInstance.stringField}');

  //And yes, we can create them recursively
  var moreComplexClassInstance = activatory.getTyped<MoreComplexClass>();
  print('MoreComplex.DateTime: ${moreComplexClassInstance.dateTimeField}');
  print('MoreComplex.Complex.String: ${moreComplexClassInstance.someComplexClass.stringField}');

  //See activatory_test.dart for full feature list
}

class MoreComplexClass {
  DateTime _dateTimeField;
  SomeComplexClass _someComplexField;

  MoreComplexClass(this._dateTimeField, this._someComplexField);
  DateTime get dateTimeField => _dateTimeField;

  SomeComplexClass get someComplexClass => _someComplexField;
}

class SomeComplexClass {
  String _stringField;
  SomeComplexClass(this._stringField);

  String get stringField => _stringField;
}

enum TestEnum { A, B, C }

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  activatory: ^0.0.20

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:activatory/activatory.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: web, other

Primary library: package:activatory/activatory.dart with components: mirrors.

Health issues and suggestions

Document public APIs. (-0.39 points)

47 out of 48 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/activatory.dart. (-1.49 points)

Analysis of lib/src/activatory.dart reported 3 hints:

line 39 col 35: Don't explicitly initialize variables to null.

line 41 col 26: Don't explicitly initialize variables to null.

line 46 col 18: Don't explicitly initialize variables to null.

Fix lib/activatory.dart. (-0.50 points)

Analysis of lib/activatory.dart reported 1 hint:

line 5 col 9: Name libraries using lowercase_with_underscores.

Fix lib/src/backends_factory.dart. (-0.50 points)

Analysis of lib/src/backends_factory.dart reported 1 hint:

line 80 col 9: Use isEmpty instead of length

Fix additional 22 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/src/customization/type_customization.dart (1 hint)
  • lib/src/activation_context.dart (Run dartfmt to format lib/src/activation_context.dart.)
  • lib/src/aliases/type_alias_registry.dart (Run dartfmt to format lib/src/aliases/type_alias_registry.dart.)
  • lib/src/backend_store.dart (Run dartfmt to format lib/src/backend_store.dart.)
  • lib/src/backends/array_backend.dart (Run dartfmt to format lib/src/backends/array_backend.dart.)
  • lib/src/backends/complex_object_backend.dart (Run dartfmt to format lib/src/backends/complex_object_backend.dart.)
  • lib/src/backends/primitive_random_backends.dart (Run dartfmt to format lib/src/backends/primitive_random_backends.dart.)
  • lib/src/backends/recursion_limiter.dart (Run dartfmt to format lib/src/backends/recursion_limiter.dart.)
  • lib/src/backends_registry.dart (Run dartfmt to format lib/src/backends_registry.dart.)
  • lib/src/ctor_info.dart (Run dartfmt to format lib/src/ctor_info.dart.)
  • lib/src/customization/argument_customization.dart (Run dartfmt to format lib/src/customization/argument_customization.dart.)
  • lib/src/customization/backend_resolve_helper.dart (Run dartfmt to format lib/src/customization/backend_resolve_helper.dart.)
  • lib/src/customization/backend_resolver.dart (Run dartfmt to format lib/src/customization/backend_resolver.dart.)
  • lib/src/customization/backend_resolver_factory.dart (Run dartfmt to format lib/src/customization/backend_resolver_factory.dart.)
  • lib/src/customization/default_ctor_resolver.dart (Run dartfmt to format lib/src/customization/default_ctor_resolver.dart.)
  • lib/src/customization/default_values_handling_strategy.dart (Run dartfmt to format lib/src/customization/default_values_handling_strategy.dart.)
  • lib/src/customization/first_ctor_resolve_strategy.dart (Run dartfmt to format lib/src/customization/first_ctor_resolve_strategy.dart.)
  • lib/src/customization/random_named_ctor_resolver.dart (Run dartfmt to format lib/src/customization/random_named_ctor_resolver.dart.)
  • lib/src/customization/random_resolver.dart (Run dartfmt to format lib/src/customization/random_resolver.dart.)
  • lib/src/customization/type_customization_registry.dart (Run dartfmt to format lib/src/customization/type_customization_registry.dart.)
  • lib/src/post_activation/fields_filler.dart (Run dartfmt to format lib/src/post_activation/fields_filler.dart.)
  • lib/src/resolve_key.dart (Run dartfmt to format lib/src/resolve_key.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
uuid ^2.0.0 2.0.2
Transitive dependencies
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
typed_data 1.1.6
Dev dependencies
mockito ^4.0.0
test ^1.0.0