{"id":18494133,"url":"https://github.com/workleap/wl-extensions-xunit","last_synced_at":"2025-04-08T22:31:02.645Z","repository":{"id":37944720,"uuid":"500926325","full_name":"workleap/wl-extensions-xunit","owner":"workleap","description":"An opinionated library that provides base unit test and fixture classes based on the Microsoft.Extensions.* packages used by modern .NET applications.","archived":false,"fork":false,"pushed_at":"2025-03-31T16:18:24.000Z","size":121,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-03-31T17:29:51.472Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","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/workleap.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-07T16:46:54.000Z","updated_at":"2025-03-20T02:42:16.000Z","dependencies_parsed_at":"2023-07-28T17:19:19.037Z","dependency_job_id":"cadf1ca4-9cbd-420e-b081-eb734d053f56","html_url":"https://github.com/workleap/wl-extensions-xunit","commit_stats":{"total_commits":16,"total_committers":5,"mean_commits":3.2,"dds":0.6875,"last_synced_commit":"34762b563728f043eafb22c389401c47c90d580e"},"previous_names":["gsoft-inc/sg-extensions-xunit","gsoft-inc/gsoft-xunit-extensions","gsoft-inc/gsoft-extensions-xunit","workleap/wl-extensions-xunit"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workleap%2Fwl-extensions-xunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workleap%2Fwl-extensions-xunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workleap%2Fwl-extensions-xunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workleap%2Fwl-extensions-xunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workleap","download_url":"https://codeload.github.com/workleap/wl-extensions-xunit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247939971,"owners_count":21021880,"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":[],"created_at":"2024-11-06T13:18:04.839Z","updated_at":"2025-04-08T22:30:57.636Z","avatar_url":"https://github.com/workleap.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workleap.Extensions.Xunit\n\nAn opinionated library that provides base unit test and fixture classes based on the `Microsoft.Extensions.*` packages used by modern .NET applications.\n\n[![nuget](https://img.shields.io/nuget/v/Workleap.Extensions.Xunit.svg?logo=nuget)](https://www.nuget.org/packages/Workleap.Extensions.Xunit/)\n[![build](https://img.shields.io/github/actions/workflow/status/gsoft-inc/wl-extensions-xunit/publish.yml?logo=github)](https://github.com/gsoft-inc/wl-extensions-xunit/actions/workflows/publish.yml)\n\n\n## Getting started\n\nThere are base classes for **unit** and **integration tests**. Each test method has its own [service collection](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-6.0) configured through a class fixture.\n\n\n### Unit tests\n\nCreate a test class that extends `BaseUnitTest\u003c\u003e` and accepts a class fixture that extends `BaseUnitFixture`.\n\nIn the fixture class, you can:\n* Override `ConfigureServices(services)` to add, remove or update dependencies for each test method.\n* Override `ConfigureConfiguration(builder)` to makes changes to the generated shared `IConfiguration`.\n* Access the generated `IConfiguration` through `this.Configuration`.\n\nIn the test class, you can:\n* Access the fixture through `this.Fixture`.\n* Access the .NET logger through `this.Logger` - it is connected to the Xunit's `ITestOutputHelper`.\n* Access the `IServiceProvider` which has been configured by the fixture through `this.Services`.\n\nBy default, unit tests come with an xunit-connected `ILogger` and an empty `IConfiguration`.\n\n### Integration tests\n\nCreate a test class that extends `BaseIntegrationTest\u003c\u003e` and accepts a class fixture that extends `BaseIntegrationFixture`.\nThey both inherit from their respective `BaseUnit*` class.\n\n* `BaseIntegrationFixture` adds a default `IHostEnvironment` where its environment name is:\n  * `Local` by default,\n  * `Test` on CI environments,\n  * overrideable by defining a `DOTNET_ENVIRONMENT` environment variable, such as in .NET modern applications.\n\n* `BaseIntegrationFixture` adds `appsettings.json` and `appsettings.{environment}.json` optional configuration providers and also an environment variable configuration provider.\n\n\n### Example\n\n```csharp\npublic class MyUnitTests : BaseUnitTest\u003cMyUnitFixture\u003e\n{\n    public MyUnitTests(MyUnitFixture fixture, ITestOutputHelper testOutputHelper)\n        : base(fixture, testOutputHelper)\n    {\n    }\n\n    [Fact]\n    public void Some_Test_Works()\n    {\n        var myClass = this.Services.GetRequiredService\u003cMyClass\u003e();\n        myClass.DoWork();\n    }\n}\n\npublic class MyUnitFixture : BaseUnitFixture\n{\n    protected override IConfigurationBuilder ConfigureConfiguration(IConfigurationBuilder builder)\n    {\n        // Executed once per fixture instance\n        return base.ConfigureConfiguration(builder).AddInMemoryCollection(new Dictionary\u003cstring, string\u003e\n        {\n            [\"My:Config:Variable\"] = \"foo\",\n        });\n        \n        // In an integration fixture, you could add concrete configuration providers, such as:\n        // builder.AddAzureKeyVault(...);\n    }\n\n    public override IServiceCollection ConfigureServices(IServiceCollection services)\n    {\n        // Executed for each test method\n        return base.ConfigureServices(services)\n            .AddTransient\u003cMyClass\u003e()\n            .AddTransient\u003cIDependency\u003e(new MyFakeDependency());\n    }\n}\n```\n\n## Contribute\n\nPlease see [CONTRIBUTING](https://github.com/gsoft-inc/wl-extensions-xunit/blob/main/CONTRIBUTING.md)\n\n## License\n\nCopyright © 2022, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkleap%2Fwl-extensions-xunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkleap%2Fwl-extensions-xunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkleap%2Fwl-extensions-xunit/lists"}