Cloud Pub/Sub (2nd Gen) Unit Test
Stay organized with collections
Save and categorize content based on your preferences.
Example unit test for a Cloud Pub/Sub-triggered function running on Cloud Functions (2nd Gen).
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis webpage provides unit test examples for Cloud Pub/Sub-triggered functions running on Cloud Functions (2nd Gen) in C#, Go, and PHP.\u003c/p\u003e\n"],["\u003cp\u003eThe C# code demonstrates testing a function that processes messages with and without text data, using \u003ccode\u003eXunit\u003c/code\u003e for assertions and a \u003ccode\u003eMemoryLogger\u003c/code\u003e for logging checks.\u003c/p\u003e\n"],["\u003cp\u003eThe Go example showcases testing \u003ccode\u003ehelloPubSub\u003c/code\u003e function with varying input data, by capturing the log output, and it utilizes the \u003ccode\u003ecloudevents\u003c/code\u003e library to simulate CloudEvents.\u003c/p\u003e\n"],["\u003cp\u003eThe PHP unit tests use \u003ccode\u003ePHPUnit\u003c/code\u003e to test the \u003ccode\u003ehelloworldPubsub\u003c/code\u003e function by simulating a CloudEvent and asserting that the function's output contains the expected greeting, handling output capture by overriding the function's logging.\u003c/p\u003e\n"],["\u003cp\u003eSetting up Application Default Credentials is required for authenticating to Cloud Run functions during local development, and a link is provided for more details on the process.\u003c/p\u003e\n"]]],[],null,[]]