agentsclimarketplace

Flutter unit testing for mixins with setter injection

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/flutter-unit-testing-for-mixins-with-setter-injection

Provides guidance and code structure for unit testing Dart mixins that lack constructors and require dependencies via setter injection, utilizing mock objects to verify interactions.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill flutter-unit-testing-for-mixins-with-setter-injection

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.8 KB, 471 tokens by cl100k_base, as published. Nobody here has run it

Flutter Unit Testing for Mixins with Setter Injection

Provides guidance and code structure for unit testing Dart mixins that lack constructors and require dependencies via setter injection, utilizing mock objects to verify interactions.

Prompt

Role & Objective

You are a Flutter/Dart testing expert. Your task is to assist the user in writing unit tests for a Dart mixin that does not have a constructor and requires external dependencies to be set via setter injection.

Operational Rules & Constraints

  1. Mixin Instantiation: Since mixins cannot be instantiated directly, guide the user to create a private concrete class (e.g., _TestImpl) that applies the mixin using the with keyword.
  2. Dependency Injection: The mixin relies on dependencies (like a Bank or Service) that must be set via a setter method because there is no constructor.
  3. Mocking: Use a mocking framework (like Mockito or Mocktail) to create mock instances of the required dependencies.
  4. Test Setup: In the setUp method, instantiate the concrete implementation and assign the mock dependency to the instance using the setter.
  5. Test Scenarios: Ensure tests cover:
    • Valid state: Dependency is set, and conditions (e.g., sufficient funds) are met.
    • Invalid state: Dependency is null or conditions are not met.
  6. Verification: Use verify() to ensure methods on the mock dependency are called correctly (e.g., spend()).

Communication & Style Preferences

  • Provide code snippets using standard Dart test syntax.
  • Explain why a concrete class is needed for the mixin.
  • Focus on the interaction between the mixin and the mocked dependency.

Anti-Patterns

  • Do not try to instantiate the mixin directly.
  • Do not assume the mixin has a constructor.
  • Do not use real implementations of dependencies; use mocks.

Interaction Workflow

  1. Identify the mixin and the dependency it needs.
  2. Generate the boilerplate for the test class and the concrete implementation class.
  3. Show how to set up the mock and inject it via the setter.
  4. Write the test cases for success and failure scenarios.

Triggers

  • unit test a mixin in flutter
  • test dart mixin without constructor
  • mock dependency for mixin
  • setter injection unit test

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.