{"id":13552073,"url":"https://github.com/smotastic/smartdata","last_synced_at":"2025-07-27T19:16:14.234Z","repository":{"id":56839827,"uuid":"393319785","full_name":"smotastic/smartdata","owner":"smotastic","description":"A generous and generic type-safe Test Data Generator","archived":false,"fork":false,"pushed_at":"2021-08-11T05:51:40.000Z","size":40,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-01T12:26:59.295Z","etag":null,"topics":["dart-package","testdata","testdatabuilder"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smotastic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-06T09:01:27.000Z","updated_at":"2024-04-08T12:04:50.000Z","dependencies_parsed_at":"2022-08-28T23:31:02.006Z","dependency_job_id":null,"html_url":"https://github.com/smotastic/smartdata","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smotastic%2Fsmartdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smotastic%2Fsmartdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smotastic%2Fsmartdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smotastic%2Fsmartdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smotastic","download_url":"https://codeload.github.com/smotastic/smartdata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222911647,"owners_count":17056714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart-package","testdata","testdatabuilder"],"created_at":"2024-08-01T12:01:58.562Z","updated_at":"2024-11-03T22:33:19.620Z","avatar_url":"https://github.com/smotastic.png","language":"Dart","readme":"# Smartdata - Creating Random Typesafe Test Data\n\nCode generator for generating type-safe generators to generate a random amount of test data in dart\n\n- [Overview](#overview)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Roadmap](#roadmap)\n\n# Overview\n\n- Add smartdata as a dependency, and smartdata_generator as a dev_dependency\n- Annotate your method with the @SmartdataInit Annotation and configure the classes for which to generate Datagenerators.\n- Run the build_runner\n- Use the generated Generator!\n\n# Installation\n\nAdd smartdata as a dependency, and the generator as a dev_dependency.\n\nhttps://pub.dev/packages/smartdata\n\n```yaml\ndependencies:\n  smartdata: [version]\n\ndev_dependencies:\n  smartdata_generator: [version]\n  # add build runner if not already added\n  build_runner:\n```\n\nRun the generator\n\n```console\ndart run build_runner build\nflutter packages pub run build_runner build\n// or watch\nflutter packages pub run build_runner watch\n```\n\n# Usage\nThere are 2 ways, on how to setup Smartdata.\nYou can automatically generate Datagenerators with the included _@SmartdataInit_ Annotation or manually create them.\n\n## Automatically generate your generators\n\nCreate your beans.\n\n```dart\nclass Dog {\n    final String breed;\n    final int age;\n    final String name;\n    Dog(this.breed, this.age, this.name);\n}\n```\nTo generate a Datagenerator for this bean, you need to initialize it.\n\n```dart\n// dog_test.dart\n@SmartdataInit(forClasses: [Dog])\nvoid init() {\n  $init();\n}\n```\n\nOnce you ran the generator, next to your _dog_test.dart_ a _dog_test.smart.dart_ will be generated.\n\n```\ndart run build_runner build\n```\n\n```dart\n// dog_test.smart.dart\nclass DogGenerator extends Generator {\n  @override\n  Simple generateRandom() {\n    final dog = Dog(\n        Smartdata.I.getSingle\u003cString\u003e(),\n        Smartdata.I.getSingle\u003cint\u003e(),\n        Smartdata.I.getSingle\u003cString\u003e()\n    );\n    return dog;\n  }\n}\n\n$init() {\n  Smartdata.put(Dog, DogGenerator());\n}\n```\n\nThe Generator supports positional arguments, named arguments and property access via implicit and explicit setters.\n\nThe generated Class can then be used in your tests.\n```dart\n@SmartdataInit(forClasses: [Dog])\nvoid init() {\n  $init();\n}\n\nvoid main() {\n  setUp(init); // make sure to call the init, to initialize the generator map\n  test('should create lots of random dogs', () {\n    final testData = Smartdata.I.get\u003cDog\u003e(50);\n    expect(testData.length, 50);\n  });\n}\n```\n## Manually create your generator\nFor flexibility or other reasons you can create your own generator.\nJust implement the included _Generator_ class, and add an instance to the Smartdata singleton.\n```dart\nclass CustomDogGenerator extends Generator\u003cDog\u003e {\n  Dog generateRandom() {\n    return Dog('German Shepherd', 1, 'Donald'); // completely random\n  }\n}\n\nvoid init() {\n  // $init() in case you also want to initialize your automatically generated generators\n  Smartdata.put(Dog, CustomDogGenerator());\n}\n```\nAnd make sure to call init before running the test.\n```dart\nvoid main() {\n  setUp(init); // make sure to call the init, to initialize the generator map\n  test('should create lots of custom random dogs', () {\n    final testData = Smartdata.I.get\u003cDog\u003e(50);\n    expect(testData.length, 50);\n  });\n}\n```\n\n# Implementation\nHow does it work? Behind the scenes is just a Generator class, which can be implemented by everyone.\n```dart\nabstract class Generator\u003cT\u003e {\n  T generateRandom();\n}\n```\nThis package provides default implementations for common primitive types, such as Strings, ints, nums and booleans.\n```dart\nclass StringGenerator extends Generator\u003cString\u003e {\n  final _random = Random();\n  final _strings = ['bulbasaur', 'ivysaur', 'venosaur'];\n  @override\n  String generateRandom() {\n    return _strings[_random.nextInt(_strings.length)];\n  }\n}\n```\nThese generators are maintained by a static Map, and can be accessed via the Smartdata Singleton.\n```dart\n// generates a list of 10 random strings\nSmartdata.I.get\u003cString\u003e(10);\n```\n\n# Examples\n\nPlease refer to the [example](https://github.com/smotastic/smartdata/tree/master/example) package, for a list of examples and how to use the Smartdata.\n\nYou can always run the examples by navigating to the examples package and executing the generator.\n\n```console\n$ dart pub get\n...\n$ dart run build_runner build\n```\n\n# Roadmap\nFeel free to open a [Pull Request](https://github.com/smotastic/smartdata/pulls), if you'd like to contribute.\n\nOr just open an issue, and i do my level best to deliver.\n","funding_links":[],"categories":["Dart"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmotastic%2Fsmartdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmotastic%2Fsmartdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmotastic%2Fsmartdata/lists"}