テスト
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Google Ads API の統合を成功させるには、テストが重要なステップとなります。これは、統合を始めたばかりの場合、アプリを維持する場合、既存の統合に新機能を追加する場合のいずれにも当てはまります。このガイドでは、Google Ads API の統合をテストする際のベスト プラクティスをいくつか紹介します。
テスト アカウントと本番環境アカウント
開発目的でテスト アカウントを利用できます。テスト アカウントを使用すると、アプリケーション コードと構成が意図したとおりに動作していることを検証できます。
ただし、テスト アカウントでテストできるのは一部の機能のみです。
テスト アカウントの制限により統合の一部の機能をテストできない場合は、代わりに本番環境アカウントを開発に使用できます。開発用の本番環境アカウントは、テスト アカウントと次の点で異なります。
- ユーザーに表示される広告を配信する
- 有効な URL を必須にする
- 広告ポリシーに準拠している必要があります
本番環境アカウントは広告を配信するため、パフォーマンス レポートをテストできる指標が生成されます。また、Google Ads API の他のすべての機能も利用できるようになります。ただし、開発に使用する場合は、特に注意が必要です。次の対策を講じることをおすすめします。
- アクセス権は、開発目的で必要なユーザーにのみ付与します。
- アカウントの 1 日の予算を低く固定します。
- テスト アカウントを使用できない場合にのみ、開発に本番環境アカウントを使用します。
そのため、統合の完全なテストを行うには、テスト用認証情報と本番環境用認証情報の両方が必要になる可能性があります。
テスト用認証情報
開発アカウントを変更しようとしたときに本番環境アカウントを誤って変更するリスクを最小限に抑えるため、本番環境アプリケーションの認証情報とは別のテスト認証情報のセットを維持することをおすすめします。
テスト認証情報のセットを作成するには:
- テスト目的でのみ使用するメール アカウント(api.test@example.com など)またはサービス アカウントを作成します。
- このユーザーまたはサービス アカウントを、テストの対象となる Google 広告アカウントの有効なユーザーとして追加します。このユーザーまたはサービス アカウントに適切なアクセスレベルを付与してください。このユーザーまたはサービス アカウントに本番環境アカウントへのアクセス権を付与しないでください。
- サービス アカウント フローではなく OAuth 2.0 ユーザー認証フローを使用している場合は、テスト ユーザー アカウントの更新トークンを生成します。
- アプリケーションのテストには、これらの新しい認証情報を使用します。開発者トークン、クライアント ID、クライアント シークレットは、どの Google 広告アカウントにアクセスできるかを判断するうえで影響がないため、テスト目的で再利用できます。
リクエストの検証
リクエストが有効かどうかをテストするだけの場合(リクエストが正しく構造化され、ポリシーに違反していないことを確認するなど)、GoogleAdsService.SearchStream
リクエストと GoogleAdsService.Search
リクエスト、およびほとんどの mutate リクエストで使用できる validate_only
フィールドを使用できます。このフィールドが特定のメソッドで使用できるかどうかを確認するには、リファレンス ドキュメントをご覧ください。
REST API
リクエストが期待どおりの出力を生成することを確認するなどのアドホック テストでは、REST API を使用するのが最も簡単な方法です。REST API にリクエストを行う際に curl を使用する方法については、REST の例をご覧ください。また、REST エクスプローラでテストすることもできます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-05 UTC。
[null,null,["最終更新日 2025-09-05 UTC。"],[[["\u003cp\u003eTesting is crucial for successful Google Ads API integration, whether you're starting fresh, maintaining an app, or adding features.\u003c/p\u003e\n"],["\u003cp\u003eUtilize test accounts for development when possible, but be aware of their limitations and consider using production accounts cautiously for features not supported by test accounts.\u003c/p\u003e\n"],["\u003cp\u003eMaintain separate test credentials, especially refresh tokens, to avoid accidental modifications to production accounts.\u003c/p\u003e\n"],["\u003cp\u003eValidate your requests using the \u003ccode\u003evalidate_only\u003c/code\u003e field to ensure they are structured correctly and comply with policies.\u003c/p\u003e\n"],["\u003cp\u003eLeverage the REST API for quick, ad hoc testing and validation of request outputs.\u003c/p\u003e\n"]]],[],null,["# Testing is an important step in building a successful Google Ads API integration,\nwhether you're just getting started, maintaining an app, or adding\nnew features to an existing integration. This guide presents some best\npractices for testing your Google Ads API integration.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nTest accounts and production accounts\n-------------------------------------\n\n[Test accounts](/google-ads/api/docs/best-practices/test-accounts) are available for\ndevelopment purposes. With test accounts, you can validate that your application\ncode and configuration are working as intended.\n\nHowever, [not all\nfeatures](/google-ads/api/docs/best-practices/test-accounts#limitations) can be tested in a\ntest account account.\n\nWhen test account limitations prevent you from testing some features in your\nintegration, you can instead use a production account for development.\nProduction accounts for development differ from test accounts in the following\nways:\n\n- Serve ads that can be seen by users\n- Require valid URLs\n- Must comply with [advertising policies](//support.google.com/adspolicy/answer/6008942)\n\nBecause production accounts serve ads, they generate metrics letting you test\nperformance reports, as well as unlocking all the other features of the\nGoogle Ads API. However, using them for development requires extra caution. We\nrecommend taking the following measures:\n\n- Only grant access to users that need it for development purposes.\n- Set a fixed, low daily account budget.\n- Use production accounts for development only when test accounts can't be used.\n\nThus, to do full testing of your integration, you will likely need both test\ncredentials and production credentials.\n\nTest credentials\n----------------\n\nTo minimize the risk of accidentally modifying production accounts when trying\nto modify development accounts, we recommend maintaining a set of test\ncredentials that are separate from your production application credentials.\n\nTo create a set of test credentials:\n\n1. Create an email account (e.g. api.test@example.com) or a service account that will be used only for testing purposes.\n2. Add this user or service account as a valid user in the Google Ads accounts you are running your tests against. Make sure you give appropriate [access levels](//support.google.com/google-ads/answer/9978556) to this user or service account. Don't give this user or service account access to **any production accounts**.\n3. If you are using the [OAuth 2.0 user authentication flow, rather than the\n service account flow](/google-ads/api/docs/get-started/choose-application-type#choose-app-type), then generate a refresh token for your test user account.\n4. Use these new credentials when testing your application. The developer token, client ID, and client secret can be reused for testing purposes, since they have no effect in determining which Google Ads accounts can be accessed.\n\nRequest validation\n------------------\n\nIf you just need to test whether a request is valid---for example, to\nverify that the request is structured correctly and does not violate\npolicies---you can use the\n[`validate_only`](/google-ads/api/docs/concepts/api-structure#mutate_validation)\nfield, which is available for `GoogleAdsService.SearchStream` and\n`GoogleAdsService.Search` requests, as well as most mutate requests.\nConsult the [reference documentation](/google-ads/api/reference/rpc/v21/overview) to verify\nwhether this field is available for a given method.\n\nREST API\n--------\n\nFor ad hoc testing, for example to validate that a request yields the expected\noutput, using the REST API is often the easiest option. Consult the [REST\nexamples](/google-ads/api/rest/examples) to learn how to use curl in making\nrequests to the REST API. Also, try testing in the\n[REST explorer](/google-ads/api/rest/try-it)."]]