{"id":37042444,"url":"https://github.com/docascode/yunit","last_synced_at":"2026-01-14T05:00:19.317Z","repository":{"id":38835722,"uuid":"196005606","full_name":"docascode/yunit","owner":"docascode","description":"A data driven testing tool for .NET using markdown and YAML","archived":false,"fork":false,"pushed_at":"2024-03-28T09:41:04.000Z","size":207,"stargazers_count":11,"open_issues_count":9,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-30T05:35:43.434Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docascode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-09T12:37:29.000Z","updated_at":"2025-09-13T14:47:42.000Z","dependencies_parsed_at":"2023-02-19T16:05:16.327Z","dependency_job_id":"a6f3da5d-1bc1-448e-b303-1b249ce599f4","html_url":"https://github.com/docascode/yunit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/docascode/yunit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docascode%2Fyunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docascode%2Fyunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docascode%2Fyunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docascode%2Fyunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docascode","download_url":"https://codeload.github.com/docascode/yunit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docascode%2Fyunit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28410055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"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":[],"created_at":"2026-01-14T05:00:18.477Z","updated_at":"2026-01-14T05:00:19.281Z","avatar_url":"https://github.com/docascode.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yunit\n\n`yunit` is a data driven testing tool for .NET using markdown and YAML.\n\nData driven tests separate your test data from test logic, making it easy to add, modify and review test cases.\n\nMarkdown and YAML are popular formats designed to be writable and readable by humans, using these formats makes testing more enjoyable.\n\n![yunit in Visual Studio](./media/yunit-in-visual-studio.png)\n\n## Getting Started\n\nWe have some [samples](samples) to demonstrate the usage of `yunit`, or you can follow these steps to scaffold a new test project:\n\n1. Create a new class library\n\n```cmd\ndotnet new console\n```\n\n2. Add NuGet reference to `yunit` and `Microsoft.NET.Test.Sdk`\n\n```cmd\ndotnet add package yunit\ndotnet add package Microsoft.NET.Test.Sdk\n```\n\n3. Create a serializable data contract to describe your test\n\n```csharp\npublic class HelloTestSpec\n{\n    public string Input;\n    public string Output;\n}\n```\n\n4. Create a public method that takes the data contract with the corresponding verification code:\n\n- Add `[YamlTest]` attribute to include test cases written in [YAML format](#writing-yaml-tests)\n- Add `[MarkdownTest]` attribute to include test cases written in [markdown format](#writing-markdown-tests)\n\n\u003e 💡 The glob pattern is relative to the current working directory, which could vary based on current build configuration and target platform. Use `~/` to denote path relative to the current git repository.\n\n```csharp\npublic class HelloTest\n{\n    [YamlTest(\"~/*.yml\")]\n    [MarkdownTest(\"~/README.md\")]\n    public void Hello(HelloTestSpec spec)\n    {\n        Assert.Equal(spec.Output, $\"Hello {spec.Input}\");\n    }\n}\n\n```\n\n5. Run your tests using `dotnet test` or Visual Studio Test Explorer. All test cases run in parallel.\n\n## Writing YAML Tests\n\nA YAML file can contain multiple YAML documents separated by `---`. Each YAML document is a test case.\n\nThe first line of comment appears as test description in Visual Studio test explorer.\n\n```yml\n# Hello YAML test!\ninput: YAML test!\noutput: Hello YAML test!\n---\n# Hello another YAML test\ninput: Another YAML test\noutput: Hello Another YAML test\n```\n\n## Writing Markdown Tests\n\nA markdown test is a specialized YAML code block in an ordinary markdown file. A normal code block starts with 3 backticks (` ``` `). A test code block starts with _at least 6_ backticks (` `````` `). \n\n``````````markdown\n# This is an ordinary markdown file\n\nUsing markdown tests, you can enhance your docs with real examples that are correct and up to date.\n\n``````yml\ninput: Markdown Test!\noutput: Hello Markdown Test!\n``````\n``````````\n\nYou can further customize how tests are extracted from markdown files in the `[MarkdownTest]` attributes.\n\n## Using `json-diff` for data driven assertion\n\nYou can use _any_ assertion library to verify your test expectations.\n\n`json-diff` is a built-in tool to write assertions in YAML that fits the `yunit` testing style. \n\n```csharp\nvar jsonDiff = new JsonDiffBuilder().Build();\njsonDiff.Verify(expected, actual, \"Test failed\");\n```\n\nThe idea of `json-dff` is to serialize your expected object and actual object into JSON and compare them using a diff algorithm.\n\n\n![Json Diff in Visual Studio](./media/json-diff-in-visual-studio.png)\n\nThe bare metal comparison expect the actual object to match exactly the same as the expected object, but you can custimize the `json-diff` pipeline to transform the expected and actual object before doing the text comparison. The built in `json-diff` pipeline comes with several handy extensions:\n\n\nmethod |  description | example\n-------|-----------------------------------------------|-------------\n`UseIgnoreNull` | Ignore the actual result of a property if the expected value is null | `{ \"a\": null }` matches `{\"a\": xxx}` where `xxx` could be anything\n`UseNegate` | Assert the actual result must not be the expected result if the expected value starts with `!` | Given an expectation of `{ \"a\": \"!value\"}` , `{\"a\": \"value\"} should fail\n`UseRegex` | The value must match a regex if the expectation looks like `/{regex}/` | `{\"a\": \"/^.*$/\" }` uses `^.*$` to match the actual value\n`UseWildcard` | Use wildcard match if the expectation contains `*` | `{\"a\": \"a*\" }` uses wildcard `a*` to match against actual value\n`UseJson` | The value must be a JSON string and its value is verified using the current pipeline, all the above rules will apply if they are configured in the pipeline  | \n`UseHtml` | The value must be an HTML string and its value is normalized before verification |\n\n`json-diff` allows you to write stateful data driven tests. The [Shopping Cart Web API sample](./samples) demonstrates a custom `json-diff` extension that preserves states between multiple web API calls for a typical web API testing scenario\n.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocascode%2Fyunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocascode%2Fyunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocascode%2Fyunit/lists"}