Skip to content

feat(dart): generate a testing skill - #6997

Merged
brianquinlan merged 25 commits into
googleapis:mainfrom
brianquinlan:skill
Aug 4, 2026
Merged

brianquinlan merged 25 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 Resolved
Comment thread internal/sidekick/dart/annotate_test.go Resolved
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 <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Brian Quinlan <[email protected]>
@brianquinlan
brianquinlan requested a review from natebosch July 24, 2026 01:27
@natebosch

Copy link
Copy Markdown
Contributor
name: google_cloud_ai_generativelanguage_v1beta-tests

@jakemac53 should we replace the underscores here?

@jakemac53

Copy link
Copy Markdown

@jakemac53 should we replace the underscores here?

Technically yes only hyphens are allowed in skill names. But I don't think it actually breaks any clients.

@brianquinlan
brianquinlan enabled auto-merge (squash) August 4, 2026 20:58
@brianquinlan
brianquinlan merged commit 53093a7 into googleapis:main Aug 4, 2026
40 checks passed
@brianquinlan
brianquinlan deleted the skill branch August 4, 2026 21:02
sofisl pushed a commit that referenced this pull request Aug 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.32.0](v0.31.1...v0.32.0)
(2026-08-04)


### Features

* **dart:** generate a testing skill
([#6997](#6997))
([53093a7](53093a7))
* **internal/librarian/php:** implement code formatting using prettier
([#7119](#7119))
([dd2b2f7](dd2b2f7))
* **internal/librarian/php:** resolve API short name and product URLs
([#7179](#7179))
([a14298b](a14298b))
* **internal/librarian/ruby:** add library initialization and wrappers
([#7181](#7181))
([3f99679](3f99679)),
refs [#7182](#7182)
[#6635](#6635)
* **internal/librarian/ruby:** add tidy function for ruby configuration
([#7115](#7115))
([aba444f](aba444f)),
refs [#6919](#6919)
* **internal/librarian/ruby:** support release please synchronization
([#7184](#7184))
([f3c1707](f3c1707)),
refs [#7185](#7185)
[#6635](#6635)
* **internal/librarian/ruby:** support ruby.wrapper_of main client gem
wrapper generation
([#7110](#7110))
([fa48762](fa48762))
* **internal/sidekick/rust:** support google.rpc.Status in hybrid crates
([#7142](#7142))
([fa8a0e6](fa8a0e6)),
refs [#6835](#6835)
* **internal/sidekick/rust:** support per_service_features in hybrid
crates ([#7112](#7112))
([0eb263a](0eb263a)),
refs [#6835](#6835)
* **internal/tool/composer:** add verification for composer tools
([#7109](#7109))
([9c7f0b1](9c7f0b1))
* **internal/tool/composer:** support local_path in ComposerTool
configuration
([#7131](#7131))
([e0d526e](e0d526e))
* **librarian/rust:** parallelize formatting
([#7192](#7192))
([625fdf8](625fdf8))
* **librarian/swift:** implement bump command
([#7136](#7136))
([72aaae1](72aaae1))
* **rust:** exclude non-streaming types from prost generation
([#7097](#7097))
([a74e30f](a74e30f)),
refs [#6835](#6835)
* **rust:** generate conversion traits for hybrid crates
([#7071](#7071))
([98d1549](98d1549)),
refs [#6835](#6835)
* **sidekick/rust:** bigquery skipped fields via librarian.yaml
([#7189](#7189))
([b07a8a7](b07a8a7))
* **sidekick/rust:** implement bidi streaming transport stubs
([#7078](#7078))
([5042693](5042693)),
refs [#6835](#6835)
* **sidekick/swift:** error on suspect library names
([#7107](#7107))
([b4df72d](b4df72d)),
refs [#6229](#6229)
* **sidekick/swift:** generate repo metadata
([#6940](#6940))
([0ea54b4](0ea54b4))
* **sidekick/swift:** support overrides for library names
([#7066](#7066))
([e9234a3](e9234a3))
* **sidekick/swift:** use polling policies
([#7123](#7123))
([fa34184](fa34184))
* **sidekick:** capture C#, PHP, and Ruby file options
([#7081](#7081))
([1d27ba8](1d27ba8))
* **sidekick:** capture C#, PHP, and Ruby file options
([#7092](#7092))
([9415901](9415901))
* **swift:** Improve module generation
([#7129](#7129))
([a0c420d](a0c420d))
* **swift:** support optional, nested fields
([#7164](#7164))
([26e5c8a](26e5c8a))
* **swift:** support repeated fields in Protobuf conversions
([#7188](#7188))
([3ee87fc](3ee87fc))


### Bug Fixes

* **cmd/librarian/Dockerfile:** bump protoc to 33.5 for Python
([#7139](#7139))
([e9da697](e9da697))
* **internal/librarian/ruby:** normalize newlines into spaces in
description and summary options
([#7134](#7134))
([f52568e](f52568e))
* **internal/librarian/ruby:** pass documentation summary as
ruby-cloud-description option
([#7105](#7105))
([d10f2f3](d10f2f3))
* **internal/librarian/ruby:** pass ruby-cloud-summary generator option
alongside description
([#7114](#7114))
([ff3a6d1](ff3a6d1))
* **internal/librarian/ruby:** preserve snippet metadata files during
regeneration
([#7085](#7085))
([d250f2b](d250f2b))
* **java:** batch formatting and run GJF twice
([#7155](#7155))
([f627180](f627180))
* **sdk.yaml:** configure ftp rest-only transport
([#7191](#7191))
([f933c87](f933c87))
* **sdk.yaml:** fix all shopping merchant titles
([#7190](#7190))
([0e22c54](0e22c54))
* **sidekick/rust:** fix prost oneof field conversion in templates
([#7093](#7093))
([709074c](709074c)),
refs [#6835](#6835)
* **sidekick/swift:** discovery enums encoding
([#7126](#7126))
([8a4ed11](8a4ed11))
* **swift:** fix sub-module imports
([#7140](#7140))
([a02c282](a02c282))
* **swift:** use let for messages without converted fields
([#7175](#7175))
([662b048](662b048))
* **tool/cmd/migrate:** exclude `.owlbot.rb` from ruby keep list
([#7108](#7108))
([e2f27e1](e2f27e1)),
refs [#6632](#6632)
* **tool/cmd/migrate:** parse WrapperOf from BUILD.bazel
([#7125](#7125))
([855a04b](855a04b)),
refs [#7127](#7127)
[#6632](#6632)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit to sofisl/librarian that referenced this pull request Aug 10, 2026
Adds a skill to help agents generate tests using fakes. The generated
skill for is `package: google_cloud_ai_generativelanguage_v1beta` is:

````markdown
---
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);
  });
}
````

---------

Signed-off-by: Brian Quinlan <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Nate Bosch <[email protected]>
sofisl pushed a commit to sofisl/librarian that referenced this pull request Aug 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.32.0](googleapis/librarian@v0.31.1...v0.32.0)
(2026-08-04)


### Features

* **dart:** generate a testing skill
([googleapis#6997](googleapis#6997))
([53093a7](googleapis@53093a7))
* **internal/librarian/php:** implement code formatting using prettier
([googleapis#7119](googleapis#7119))
([dd2b2f7](googleapis@dd2b2f7))
* **internal/librarian/php:** resolve API short name and product URLs
([googleapis#7179](googleapis#7179))
([a14298b](googleapis@a14298b))
* **internal/librarian/ruby:** add library initialization and wrappers
([googleapis#7181](googleapis#7181))
([3f99679](googleapis@3f99679)),
refs [googleapis#7182](googleapis#7182)
[googleapis#6635](googleapis#6635)
* **internal/librarian/ruby:** add tidy function for ruby configuration
([googleapis#7115](googleapis#7115))
([aba444f](googleapis@aba444f)),
refs [googleapis#6919](googleapis#6919)
* **internal/librarian/ruby:** support release please synchronization
([googleapis#7184](googleapis#7184))
([f3c1707](googleapis@f3c1707)),
refs [googleapis#7185](googleapis#7185)
[googleapis#6635](googleapis#6635)
* **internal/librarian/ruby:** support ruby.wrapper_of main client gem
wrapper generation
([googleapis#7110](googleapis#7110))
([fa48762](googleapis@fa48762))
* **internal/sidekick/rust:** support google.rpc.Status in hybrid crates
([googleapis#7142](googleapis#7142))
([fa8a0e6](googleapis@fa8a0e6)),
refs [googleapis#6835](googleapis#6835)
* **internal/sidekick/rust:** support per_service_features in hybrid
crates ([googleapis#7112](googleapis#7112))
([0eb263a](googleapis@0eb263a)),
refs [googleapis#6835](googleapis#6835)
* **internal/tool/composer:** add verification for composer tools
([googleapis#7109](googleapis#7109))
([9c7f0b1](googleapis@9c7f0b1))
* **internal/tool/composer:** support local_path in ComposerTool
configuration
([googleapis#7131](googleapis#7131))
([e0d526e](googleapis@e0d526e))
* **librarian/rust:** parallelize formatting
([googleapis#7192](googleapis#7192))
([625fdf8](googleapis@625fdf8))
* **librarian/swift:** implement bump command
([googleapis#7136](googleapis#7136))
([72aaae1](googleapis@72aaae1))
* **rust:** exclude non-streaming types from prost generation
([googleapis#7097](googleapis#7097))
([a74e30f](googleapis@a74e30f)),
refs [googleapis#6835](googleapis#6835)
* **rust:** generate conversion traits for hybrid crates
([googleapis#7071](googleapis#7071))
([98d1549](googleapis@98d1549)),
refs [googleapis#6835](googleapis#6835)
* **sidekick/rust:** bigquery skipped fields via librarian.yaml
([googleapis#7189](googleapis#7189))
([b07a8a7](googleapis@b07a8a7))
* **sidekick/rust:** implement bidi streaming transport stubs
([googleapis#7078](googleapis#7078))
([5042693](googleapis@5042693)),
refs [googleapis#6835](googleapis#6835)
* **sidekick/swift:** error on suspect library names
([googleapis#7107](googleapis#7107))
([b4df72d](googleapis@b4df72d)),
refs [googleapis#6229](googleapis#6229)
* **sidekick/swift:** generate repo metadata
([googleapis#6940](googleapis#6940))
([0ea54b4](googleapis@0ea54b4))
* **sidekick/swift:** support overrides for library names
([googleapis#7066](googleapis#7066))
([e9234a3](googleapis@e9234a3))
* **sidekick/swift:** use polling policies
([googleapis#7123](googleapis#7123))
([fa34184](googleapis@fa34184))
* **sidekick:** capture C#, PHP, and Ruby file options
([googleapis#7081](googleapis#7081))
([1d27ba8](googleapis@1d27ba8))
* **sidekick:** capture C#, PHP, and Ruby file options
([googleapis#7092](googleapis#7092))
([9415901](googleapis@9415901))
* **swift:** Improve module generation
([googleapis#7129](googleapis#7129))
([a0c420d](googleapis@a0c420d))
* **swift:** support optional, nested fields
([googleapis#7164](googleapis#7164))
([26e5c8a](googleapis@26e5c8a))
* **swift:** support repeated fields in Protobuf conversions
([googleapis#7188](googleapis#7188))
([3ee87fc](googleapis@3ee87fc))


### Bug Fixes

* **cmd/librarian/Dockerfile:** bump protoc to 33.5 for Python
([googleapis#7139](googleapis#7139))
([e9da697](googleapis@e9da697))
* **internal/librarian/ruby:** normalize newlines into spaces in
description and summary options
([googleapis#7134](googleapis#7134))
([f52568e](googleapis@f52568e))
* **internal/librarian/ruby:** pass documentation summary as
ruby-cloud-description option
([googleapis#7105](googleapis#7105))
([d10f2f3](googleapis@d10f2f3))
* **internal/librarian/ruby:** pass ruby-cloud-summary generator option
alongside description
([googleapis#7114](googleapis#7114))
([ff3a6d1](googleapis@ff3a6d1))
* **internal/librarian/ruby:** preserve snippet metadata files during
regeneration
([googleapis#7085](googleapis#7085))
([d250f2b](googleapis@d250f2b))
* **java:** batch formatting and run GJF twice
([googleapis#7155](googleapis#7155))
([f627180](googleapis@f627180))
* **sdk.yaml:** configure ftp rest-only transport
([googleapis#7191](googleapis#7191))
([f933c87](googleapis@f933c87))
* **sdk.yaml:** fix all shopping merchant titles
([googleapis#7190](googleapis#7190))
([0e22c54](googleapis@0e22c54))
* **sidekick/rust:** fix prost oneof field conversion in templates
([googleapis#7093](googleapis#7093))
([709074c](googleapis@709074c)),
refs [googleapis#6835](googleapis#6835)
* **sidekick/swift:** discovery enums encoding
([googleapis#7126](googleapis#7126))
([8a4ed11](googleapis@8a4ed11))
* **swift:** fix sub-module imports
([googleapis#7140](googleapis#7140))
([a02c282](googleapis@a02c282))
* **swift:** use let for messages without converted fields
([googleapis#7175](googleapis#7175))
([662b048](googleapis@662b048))
* **tool/cmd/migrate:** exclude `.owlbot.rb` from ruby keep list
([googleapis#7108](googleapis#7108))
([e2f27e1](googleapis@e2f27e1)),
refs [googleapis#6632](googleapis#6632)
* **tool/cmd/migrate:** parse WrapperOf from BUILD.bazel
([googleapis#7125](googleapis#7125))
([855a04b](googleapis@855a04b)),
refs [googleapis#7127](googleapis#7127)
[googleapis#6632](googleapis#6632)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
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.

3 participants