# Google Cloud Iam V1 Tests

> Use this skill when writing tests for code that uses package:google_cloud_iam_v1

- Skill: `googleapis/google-cloud-iam-v1-tests` (Agent Skill)
- Install (CLI): `npx skillmds@latest add googleapis/google-cloud-iam-v1-tests`
- Raw SKILL.md: https://api.skillmd.com/api/skills/googleapis/google-cloud-iam-v1-tests/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: googleapis (https://skillmd.com/u/googleapis)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/googleapis/google-cloud-iam-v1-tests

---


## Testing with Fakes

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

- Code that uses `IAMPolicy` can be tested by injecting the
  fake `FakeIAMPolicy`.

Import the fakes from the testing library:

```dart
import 'package:google_cloud_iam_v1/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_iam_v1/iam.dart';
import 'package:google_cloud_iam_v1/testing.dart';

final fake = FakeIAMPolicy(
  setIamPolicy: (request) async {
    // Assert request contents here if needed.
    return Policy();
  },
);
```

### 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 overridden will throw an
`UnsupportedError`.

```dart
import 'package:google_cloud_iam_v1/iam.dart';
import 'package:google_cloud_iam_v1/testing.dart';

final class MyFakeIAMPolicy extends FakeIAMPolicy {
  @override
  Future<Policy> setIamPolicy(
    SetIamPolicyRequest request,
  ) async {
    // Assert request contents here if needed.
    return Policy();
  }
}
```

## A Simple Test

```dart
import 'package:google_cloud_iam_v1/iam.dart';
import 'package:google_cloud_iam_v1/testing.dart';
import 'package:test/test.dart';

Future<void> functionUnderTest(IAMPolicy service) async {
  // Application logic here.
  await service.setIamPolicy(SetIamPolicyRequest());
  // More application logic here.
}

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

