{"id":30384163,"url":"https://github.com/starcruisestudios/phxtest","last_synced_at":"2025-08-21T01:17:39.992Z","repository":{"id":65411276,"uuid":"541419862","full_name":"StarCruiseStudios/PhxTest","owner":"StarCruiseStudios","description":"A toolkit for improving self documentation, readability, and debugging of tests.","archived":false,"fork":false,"pushed_at":"2024-05-05T06:28:51.000Z","size":667,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-19T10:05:55.954Z","etag":null,"topics":["bdd","csharp","nunit","validation"],"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/StarCruiseStudios.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-26T05:21:20.000Z","updated_at":"2024-05-05T06:28:55.000Z","dependencies_parsed_at":"2023-02-14T17:46:09.458Z","dependency_job_id":null,"html_url":"https://github.com/StarCruiseStudios/PhxTest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StarCruiseStudios/PhxTest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StarCruiseStudios","download_url":"https://codeload.github.com/StarCruiseStudios/PhxTest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxTest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271411830,"owners_count":24755026,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bdd","csharp","nunit","validation"],"created_at":"2025-08-21T01:17:38.973Z","updated_at":"2025-08-21T01:17:39.982Z","avatar_url":"https://github.com/StarCruiseStudios.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHX.Test\n\nA toolkit for improving self documentation, readability, and debugging of tests.\n\nPHX.Test assists in setting up a BDD given/when/then structure for readability\nand test self-documentation, and it logs each provided value, input, output,\ncondition, action, and assertion in human readable text to assist in debugging\nwhat is occurring in a test and what is going wrong.\n\nThis test class using Phx.Test:\n\n```csharp\n[TestFixture]\n[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]\n[Parallelizable(ParallelScope.All)]\npublic class AccumulatorTests : LoggingTestClass {\n    [Test]\n    public void APositiveValueCanBeAdded() {\n        var accumulator = Given(\"An accumulator instance\", () =\u003e new Accumulator());\n        var valueToAdd = Given(\"A positive number\", () =\u003e 10);\n\n        When(\"The value is added to the accumulator\", () =\u003e accumulator.Add(valueToAdd));\n\n        Then(\"The accumulator has the expected total\",\n                10,\n                (expected) =\u003e {\n                    Verify.That(accumulator.Total.IsEqualTo(expected));\n                });\n    }\n\n    [Test]\n    public void ANegativeValueCannotBeAdded() {\n        var accumulator = Given(\"An accumulator instance\", () =\u003e new Accumulator());\n        var valueToAdd = Given(\"A negative number\", () =\u003e -10);\n\n        var action = DeferredWhen(\"The value is added to the accumulator\",\n                () =\u003e accumulator.Add(valueToAdd));\n\n        Then(\"The expected exception is thrown\",\n                typeof(InvalidOperationException),\n                (expectedExceptionType) =\u003e { Verify.That(action.DoesThrow(expectedExceptionType)); });\n    }\n}\n```\n\nWill generate the following output:\n\n```markdown\n----------------------------------------\n## Phx.Test.Example.AccumulatorTests.APositiveValueCanBeAdded\n\n**Given:**\n* An accumulator instance : `Phx.Test.Example.Accumulator` -\u003e **PASSED**\n* A positive number : `10` -\u003e **PASSED**\n\n**When:**\n* The value is added to the accumulator -\u003e **PASSED**\n\n**Then:**\n* The accumulator has the expected total (`10`) -\u003e **PASSED**\n\n\u003e TestResult: **PASSED**\n\n \n----------------------------------------\n## Phx.Test.Example.AccumulatorTests.ANegativeValueCannotBeAdded\n\n**Given:**\n* An accumulator instance : `Phx.Test.Example.Accumulator` -\u003e **PASSED**\n* A negative number : `-10` -\u003e **PASSED**\n\n**When:**\n* The value is added to the accumulator -\u003e **DEFERRED**\n\n**Then:**\n* A deferred action is executed: `The value is added to the accumulator` -\u003e **PASSED**\n* The expected exception is thrown (`System.InvalidOperationException`) -\u003e **PASSED**\n\n\u003e TestResult: **PASSED**\n```\n\n## Set up\n\nPHX.Test can be installed as a Nuget package using the .NET CLI.\n\n```shell\ndotnet add package Phx.Test\n```\n\n## Getting Started\n\nPHX.Test is built on top of NUnit, and the only thing that is necessary to get\nstarted is to write a test class that extends `Phx.Test.LoggingTestClass`.\n```csharp\n[TestFixture]\npublic class AccumulatorTests : LoggingTestClass {\n    // ...\n}\n```\n\nThe class will have access to the `Given`, `When`, `DeferredWhen`, `Then`, and \n`Log` methods used to log test values and actions.\n\nFollowing conventions of BDD:\n* `Given` should be used to log test preconditions and input values, and will\n  return the value for use in later test steps.\n* `When` should be used to log the action under test and returns the result of\n  the action for validation.\n* `DeferredWhen` should be used when execution of the action under test must be\n  delayed to validate it correctly. This is typically used in conjunction with\n  a Then step to verify an exception was or was not thrown. If a deferred action\n  is not executed by the time the test completes, the test will fail.\n* `Then` should be used to validate the results of the action. An expected value\n  can be passed in to be logged.\n* `Log` can also be used to log any test messages that you want to appear inline\n  in the test logs.\n* `Pending` is used to indicate that a test's implementation is pending \n  completion. By default, pending tests will cause a failure. Setting the\n  `PHX_TEST_FAIL_ON_PENDING` env var to `false` or overriding the test class's \n  `FailOnPending` property to return `false` will cause the test to complete \n  successfully and ignore the pending scenario.\n\n## Additional Test Utilities\nPHX.Test also provides utilities to make writing and debugging tests easier.\n\n### TestDisposable\n`TestDisposable` is an `IDisposable` that allows you to manually initialize it\nin a desired disposed state, and to check the current disposed state.\n\n```csharp\nvar disposable = new TestDisposable(false);\nVerify.That(disposable.IsDisposed.IsFalse());\n\ndisposable.Dispose();\nVerify.That(disposable.IsDisposed.IsTrue());\n```\n\nThis can be useful when testing types that contain or manipulate `IDisposable`\ninstances.\n\n### TestException\n`TestException` is a simple exception type that can be thrown from mocked or\ntest code and is easily distinguishable from any exception that may be thrown\nfrom production code.\n\n```csharp\nvar action = () =\u003e { \n    PerformAction(() =\u003e { throw new TestException(\"This is a test.\"); } \n}\n\n// We know `TestException` was thrown by our test code and not something else\n// inside of the `PerformAction` method.\nVerify.That(action.DoesThrow\u003cTestException\u003e());\n```\n\n### Verify\n`Verify` is a [PHX.Validation](https://github.com/StarCruiseStudios/PhxValidation)\nvalidator that will throw a `VerificationFailedException` when the validation\nfails.\n\nTest validator extension methods are also provided to help verify that an\nexception was thrown by an `Action`.\n```csharp\nVerify.That(action.DoesThrow\u003cTestException\u003e());\n```\n\n---\n\n\u003cdiv align=\"center\"\u003e\nCopyright (c) 2022 Star Cruise Studios LLC. All rights reserved.\u003cbr/\u003e\nLicensed under the Apache License, Version 2.0.\u003cbr/\u003e\nSee http://www.apache.org/licenses/LICENSE-2.0 for full license information.\u003cbr/\u003e\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarcruisestudios%2Fphxtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarcruisestudios%2Fphxtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarcruisestudios%2Fphxtest/lists"}