{"id":19054486,"url":"https://github.com/datadog/dd-sdk-swift-testing","last_synced_at":"2025-04-24T03:21:54.980Z","repository":{"id":41804939,"uuid":"299370586","full_name":"DataDog/dd-sdk-swift-testing","owner":"DataDog","description":"Datadog Test Optimisation framework for Swift / ObjC","archived":false,"fork":false,"pushed_at":"2025-04-11T17:15:44.000Z","size":1998,"stargazers_count":18,"open_issues_count":3,"forks_count":6,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-18T12:17:13.921Z","etag":null,"topics":["observability","unit-testing"],"latest_commit_sha":null,"homepage":"https://docs.datadoghq.com/tests/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DataDog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-28T16:39:18.000Z","updated_at":"2025-03-19T16:31:03.000Z","dependencies_parsed_at":"2024-01-18T05:23:21.589Z","dependency_job_id":"0e940743-23a1-499f-997e-b1df46ed84c9","html_url":"https://github.com/DataDog/dd-sdk-swift-testing","commit_stats":null,"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdd-sdk-swift-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdd-sdk-swift-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdd-sdk-swift-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DataDog%2Fdd-sdk-swift-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DataDog","download_url":"https://codeload.github.com/DataDog/dd-sdk-swift-testing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552787,"owners_count":21449275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["observability","unit-testing"],"created_at":"2024-11-08T23:38:32.134Z","updated_at":"2025-04-24T03:21:54.947Z","avatar_url":"https://github.com/DataDog.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Datadog SDK for Swift Test Optimization\n\nThis SDK is part of Datadog's [Test Optimization](https://docs.datadoghq.com/tests/) product.\nA more comprehensive and updated documentation can be found at [Test Optimization - Swift](https://docs.datadoghq.com/tests/setup/swift/).\n\n## Getting Started\n\nLink your test targets with the framework (you can use SPM or direct linking )\n\nSet the following environment variables to the Test Action:\n\n```sh\nDD_TEST_RUNNER=1\nDD_API_KEY=\u003cyour current api key\u003e\nSRCROOT=$(SRCROOT)\n```\n\nYou my want to set other environment variables to\n\n```shell\nDD_ENV=\u003cThe environment you want to report\u003e\nDD_SERVICE=\u003cThe name of the service you want to report\u003e\nDD_SITE=\u003cThe Datadog site to upload results to\u003e\n```\n\nDepending on your CI service, you must also set the environment variables to be read from the test executions. See [CI Providers Environment Variables](https://docs.datadoghq.com/tests/setup/swift/#ci-provider-environment-variables) for details of your specific CI.\n\n## UI Tests\n\nFor UI Tests, this SDK will automatically integrate with the RUM SDK in your application. Environment variables only need to be set in the test target, since the framework automatically injects these values to the application.\n\nIf your don't use RUM SDK, this SDK can be linked with the Application too. Don't ship your app with this SDK, it should be linked only to the test builds.\n\n## Auto Instrumentation\n\n\u003eBoolean variables can use any of: \"1\",\"0\",\"true\",\"false\", \"YES\", \"NO\"\n\u003eString List variables accepts a list of elements separated by \",\" or \";\"\n\n### Enabling Logs Auto Instrumentation\n\n```shell\nDD_ENABLE_STDOUT_INSTRUMENTATION # Captures messages written to `stdout` (e.g `print()` ) and reports them as Logs. (Implies charges for Logs product) (Boolean)\nDD_ENABLE_STDERR_INSTRUMENTATION #  Captures messages written to `stderr` (e.g `NSLog()`, UITest steps ) and reports them as Logs. (Implies charges for Logs product) (Boolean)\n```\n\n### Configuring Network Auto Instrumentation\n\nFor Network autoinstrumentation there are other settings that you can configure\n\n```shell\nDD_DISABLE_NETWORK_INSTRUMENTATION # Disables all network instrumentation (Boolean)\nDD_DISABLE_HEADERS_INJECTION # Disables all injection of tracing headers (Boolean)\nDD_INSTRUMENTATION_EXTRA_HEADERS # Specific extra headers that you want the tool to log (String List)\nDD_EXCLUDED_URLS # Urls that you dont want to log or inject headers into(String List)\nDD_ENABLE_RECORD_PAYLOAD # It enables reporting a subset of the payloads in requests and responses (Boolean)\nDD_MAX_PAYLOAD_SIZE # It sets the maximum size that will be reported from the payload, 1024 by default (Integer)\n```\n\nYou can also disable or enable specific autoinstrumentation in some of the tests from Swift or Objective-C by importing the module `DatadogSDKTesting` and using the class: `DDInstrumentationControl`.\n\n### Disable crash handling\n\nYou should never need to do it, but in some ***very specific cases*** you may want to disable crash reporting for tests (e.g. you want to test your own crash handler, ... ):\n```shell\nDD_DISABLE_CRASH_HANDLER # Disables crash handling and reporting. (Boolean) WARNING, read note below\n```\n\u003e You must know that if you disable crash reporting, crashing tests wont be reported to the backend and wont appear as a failure. If you really, really need to do this for any of your tests, run it as a totally separated target, so you dont disable it for the rest of the tests\n\n## Custom tags\n\n### Environment variables\n\nYou can use `DD_TAGS` environment variable. It must contain pairs of `key:tag` separated by spaces. For example:\n\n```shell\nDD_TAGS=\"tag-key-0:tag-value-0 tag-key-1:tag-value-1\"\n```\n\nIf one of your values starts with the `$` character, it will be replaced with the environment variable with the same name if it exists, example:\n\n```shell\nDD_TAGS=\"home:$HOME\"\n```\nIt also supports replacing a environment variable at the beggining of the value if contains non env variables supported characters (`a-z`,  `A-Z` or `_`):\n\n```shell\nFOO = BAR\nDD_TAGS=\"key1:$FOO-v1\" # expected: key1:BAR-v1\n```\n\n### Inside test code\n\nYou can add custom tags inside your test methods. The static property `DDTest.current` will return the current test instance if called inside the test method scope.\n\n```swift\n// Somewhere inside the test method\nDDTest.current!.setTag(key: \"key1\", value: \"value1\")\n```\n\n## Using OpenTelemetry (only for Swift)\n\nThe Datadog Swift testing framework uses [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-swift) as the tracing technology under the hood. You can access the OpenTelemetry tracer using `DDInstrumentationControl.openTelemetryTracer` and can use any OpenTelemetry api. For example, for adding a tag/attribute:\n\n```swift\nimport DatadogSDKTesting\nimport OpenTelemetryApi\n\nlet tracer = DDInstrumentationControl.openTelemetryTracer as? Tracer\nlet span = tracer?.spanBuilder(spanName: \"ChildSpan\").startSpan()\nspan?.setAttribute(key: \"OTTag2\", value: \"OTValue2\")\nspan?.end()\n```\n\nThe test target needs to link explicitly with `opentelemetry-swift`.\n\n## Using Info.plist for configuration\n\nAlternatively to setting environment variables, all configuration values can be provided by adding them to the `Info.plist` file of the Test bundle (not the App bundle). If the same setting is set both in an environment variable and in the `Info.plist` file, the environment variable takes precedence.\n\n## Contributing\n\nPull requests are welcome. First, open an issue to discuss what you would like to change. For more information, read the [Contributing Guide](CONTRIBUTING.md).\n\n## License\n\n[Apache License, v2.0](LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fdd-sdk-swift-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatadog%2Fdd-sdk-swift-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatadog%2Fdd-sdk-swift-testing/lists"}