Skip to content

feat(dart): generate a testing skill#6997

Open
brianquinlan wants to merge 16 commits into
googleapis:mainfrom
brianquinlan:skill
Open

feat(dart): generate a testing skill#6997
brianquinlan wants to merge 16 commits into
googleapis:mainfrom
brianquinlan:skill

Conversation

@brianquinlan

@brianquinlan brianquinlan commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Adds a skill to help agents generate tests using fakes. The generated skill for is package: google_cloud_ai_generativelanguage_v1beta is:

---
name: google_cloud_ai_generativelanguage_v1beta-tests
description: >-
  Use this skill when writing tests for code that uses
  package:google_cloud_ai_generativelanguage_v1beta
---

## Testing with Fakes

Most unit tests should use fakes instead of making network requests to Google
services.

- Code that uses `CacheService` can be tested by injecting the
  fake `FakeCacheService`.
- Code that uses `DiscussService` can be tested by injecting the
  fake `FakeDiscussService`.
- Code that uses `FileService` can be tested by injecting the
  fake `FakeFileService`.
- Code that uses `GenerativeService` can be tested by injecting the
  fake `FakeGenerativeService`.
- Code that uses `ModelService` can be tested by injecting the
  fake `FakeModelService`.
- Code that uses `PermissionService` can be tested by injecting the
  fake `FakePermissionService`.
- Code that uses `PredictionService` can be tested by injecting the
  fake `FakePredictionService`.
- Code that uses `RetrieverService` can be tested by injecting the
  fake `FakeRetrieverService`.
- Code that uses `TextService` can be tested by injecting the
  fake `FakeTextService`.

Import the fakes from the testing library:

```dart
import 'package:google_cloud_ai_generativelanguage_v1beta/testing.dart';
```

### Option A: Using Constructor Closures (Recommended)
You can inject behavior by passing optional function callbacks to the fake's
constructor. Methods that are not provided will throw an `UnsupportedError`.

```dart
import 'package:google_cloud_ai_generativelanguage_v1beta/generativelanguage.dart';
import 'package:google_cloud_ai_generativelanguage_v1beta/testing.dart';

final fake = FakeFileService(
  createFile: (request) async {
    // Assert request contents here if needed.
    return CreateFileResponse();
  },
);
```

### Option B: Subclassing the Fake
For more complex test setups or shared states, you can subclass the fake and
override its methods. Methods that are not overriden will throw an
`UnsupportedError`.

```dart
import 'package:google_cloud_ai_generativelanguage_v1beta/generativelanguage.dart';
import 'package:google_cloud_ai_generativelanguage_v1beta/testing.dart';

final class MyFakeFileService extends FakeFileService {
  @override
  Future<CreateFileResponse> createFile(
    CreateFileRequest request,
  ) async {
    // Assert request contents here if needed.
    return CreateFileResponse();
  }
}
```

## A Simple Test

```dart
import 'package:google_cloud_ai_generativelanguage_v1beta/generativelanguage.dart';
import 'package:google_cloud_ai_generativelanguage_v1beta/testing.dart';
import 'package:test/test.dart';

Future<void> functionUnderTest(FileService service) async {
  // Application logic here.
  await service.createFile(CreateFileRequest());
  // More application logic here.
}

void main() {
  test('test', () async {
    final fake = FakeFileService(
      createFile: (request) async {
          // Assert request contents here.
          return CreateFileResponse();
      },
    );
    // Instead of verifying that `functionUnderTest`, you should verify the
    // relevant properties of the result.
    await expectLater(functionUnderTest(fake), completes);
  });
}

@brianquinlan
brianquinlan requested a review from a team as a code owner July 23, 2026 18:16

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for generating a testing guide (SKILL.md) for Dart packages, utilizing a new findExampleMethod helper to select the best candidate service and method for documentation examples. Feedback on the changes highlights a bug where the returned variables from findExampleMethod are swapped, and recommends using a fixed seed for random shuffling in tests to ensure determinism.

Comment thread internal/sidekick/dart/annotate.go Outdated
Comment thread internal/sidekick/dart/annotate_test.go Outdated
brianquinlan and others added 6 commits July 23, 2026 11:23
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Brian Quinlan <bquinlan@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Brian Quinlan <bquinlan@google.com>
@brianquinlan
brianquinlan requested a review from natebosch July 24, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants