AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Dart Add Unit Test

skill-dhruvanbhalara-skills-dart-add-unit-test · by dhruvanbhalara

Write unit tests with mocking and coverage analysis for pure Dart projects and CLI apps. Use when testing business logic, generating mocks with Mockito or mocktail, or measuring test coverage.

No reviews yet
0 installs
29 views
0.0% view→install

Install

$ agentstack add skill-dhruvanbhalara-skills-dart-add-unit-test

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-dhruvanbhalara-skills-dart-add-unit-test)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
3mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Dart Add Unit Test? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Dart Testing Suite

Contents

  • [Unit Testing](#unit-testing)
  • [Mocking Dependencies](#mocking-dependencies)
  • [Test Coverage](#test-coverage)
  • [Workflow: Testing Execution](#workflow-testing-execution)

Unit Testing

Utilize package:test as the standard testing library for Dart CLI and backend applications.

  • Organize test files to mirror the lib directory structure. Append _test.dart to test files.
  • Group related tests using the group() function.
  • Use setUp() and tearDown() for shared test state.
  • Write pure logic inside Domain/BLoC and extract to static pure functions for 100% unit test coverage.
  • Use string interpolation for test group names: group('$ClassName', ...)
  • Structure each test using the Arrange-Act-Assert (Given-When-Then) convention:
  • Arrange: Set up mocks, create instances, prepare input data.
  • Act: Call the method under test.
  • Assert: Verify the output or side effects.
  • Separate setup from verification to keep tests readable and maintainable.

Mocking Dependencies

mocktail vs mockito Decision

| Criteria | mocktail (Recommended) | mockito | |---|---|---| | Code generation | Not needed | Requires build_runner | | Setup speed | Fast (extend Mock) | Slower (annotation + codegen) | | Null safety | Full support | Full support | | API style | when(() => mock.method()) | when(mock.method()) | | Best for | Most projects, fast iteration | Large projects with complex APIs |

Rule: Default to mocktail (no codegen, faster setup). Use mockito only when you need @GenerateNiceMocks for complex APIs with many overloads.

mocktail Setup (Recommended)

import 'package:mocktail/mocktail.dart';

// Create mock — no code generation needed
class MockUserRepository extends Mock implements UserRepository {}

void main() {
  late MockUserRepository mockRepo;

  setUp(() {
    mockRepo = MockUserRepository();
  });

  test('fetches user successfully', () {
    // Arrange
    when(() => mockRepo.getUser('1'))
        .thenAnswer((_) async => const User(id: '1', name: 'Alice'));

    // Act
    final user = await mockRepo.getUser('1');

    // Assert
    expect(user.name, 'Alice');
    verify(() => mockRepo.getUser('1')).called(1);
  });
}

mockito Setup (Code-Gen)

import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';

@GenerateNiceMocks([MockSpec()])
import 'user_test.mocks.dart';  // Generated by: dart run build_runner build

Verification APIs

| API | Purpose | |---|---| | verify(() => mock.method()).called(1) | Assert method was called exactly once | | verifyNever(() => mock.method()) | Assert method was never called | | verifyNoMoreInteractions(mock) | Assert no unchecked interactions remain | | verifyInOrder([...]) | Assert methods were called in specific order | | reset(mock) | Clear all stubs and interactions |

Registering Fallback Values

For methods with custom types as parameters:

setUpAll(() {
  registerFallbackValue(const User(id: '0', name: 'fallback'));
});

Test Coverage

  • Target 100% logic coverage for domain models and business logic.
  • Run coverage with dart test --coverage=coverage or flutter test --coverage.
  • See dart-coverage skill for detailed LCOV/HTML report generation.

Workflow: Testing Execution

Follow this sequential workflow when testing a Dart feature. Copy the checklist to track progress.

Task Progress

  • [ ] Step 1: Write Unit Tests. Focus on core business logic. Ensure files end with _test.dart.
  • [ ] Step 2: Generate Mocks. Run dart run build_runner build to generate mocks if using Mockito.
  • [ ] Step 3: Run Tests. Execute dart test.
  • [ ] Step 4: Check Coverage. Run dart test --coverage=coverage and verify coverage targets are met.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.