{"id":17867106,"url":"https://github.com/cdhunt/testing","last_synced_at":"2025-04-02T22:13:29.899Z","repository":{"id":145810379,"uuid":"123933256","full_name":"cdhunt/testing","owner":"cdhunt","description":"A unit test runner for PowerShell","archived":false,"fork":false,"pushed_at":"2018-03-28T19:16:22.000Z","size":675,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T12:30:36.564Z","etag":null,"topics":["testing","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","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/cdhunt.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-05T14:41:49.000Z","updated_at":"2018-03-08T01:54:05.000Z","dependencies_parsed_at":"2024-04-19T10:01:08.622Z","dependency_job_id":null,"html_url":"https://github.com/cdhunt/testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdhunt%2Ftesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdhunt%2Ftesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdhunt%2Ftesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdhunt%2Ftesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdhunt","download_url":"https://codeload.github.com/cdhunt/testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246899666,"owners_count":20851898,"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":["testing","unit-testing"],"created_at":"2024-10-28T09:43:56.397Z","updated_at":"2025-04-02T22:13:29.884Z","avatar_url":"https://github.com/cdhunt.png","language":"PowerShell","readme":"# Testing\n\nA unit test runner for PowerShell.\n\n_Latest Build Status_\n\n[![Build status](https://ci.appveyor.com/api/projects/status/nuoyux0t0pc47m5q?svg=true)](https://ci.appveyor.com/project/cdhunt/testing)\n\n_Master Branch Status_\n\n[![Build status](https://ci.appveyor.com/api/projects/status/nuoyux0t0pc47m5q/branch/master?svg=true)](https://ci.appveyor.com/project/cdhunt/testing/branch/master)\n\n## Why\n\nThere's already [Pester](https://github.com/pester/pester) so what's the point of this?\n\nPester was designing using [BDD-style](https://en.wikipedia.org/wiki/Behavior-driven_development) [DSL](https://en.wikipedia.org/wiki/Domain-specific_language).\nThat makes the test files read a bit like English and therefor self documenting.\nThat is a great feature, but the downside is it requires a lot of boilerplate to define each test.\nAfter working with some other unit test frameworks in other languages,\nI've grown to appreciate their focus on creating and running lots of tests quickly.\nSo, that is why I started messing around with a new module to write and run unit tests.\nThat is the primary intention of this module.\nThe assertions are built using Jakub's [Assert](https://github.com/nohwnd/Assert) module.\n\n## Syntax of a Test\n\n```powershell\nfunction Test-Numbers ([PSTypeName('Testing')]$t)\n{\n    $tests = @(\n        @{num=1;expected=1},\n        @{num=2;expected=1},\n        @{num=\"three\";expected=1}\n    )\n\n    foreach ($test in $tests) {\n        $actual = $test.num * 1\n        $t.Equal($test.expected, $actual)\n    }\n\n```\n\nA test is a function with the `Test` verb and a single parameter with the `[PSTypeName('Testing')]` attribute.\nThe function needs at least one assertion method called like `$t.Equal($expected, $actual)`.\n\n## Assertions\n\n### Equal\n\nParameters: [object]Expected, [object]Actual\n\nTest `$actual -eq expected`\n\n_example_\n\n```powershell\n$actual = 1 * 2\n$t.Equal(2, $actual)\n```\n### Like\n\nParameters: [string]Expected, [string]Actual, [array]Values\n\nTest `$actual -like $expected`\n\nOptionally, take an array of values and format `$expected -f $values`\n\n_example_\n\n```powershell\n$t.Like(\"{0} {1} is nice\", $actual, @($FirstName, $LastName))\n```\n\n## Invoking\n\n`Invoke-Testing [-Path] \u003cstring[]\u003e [-Exit] [-Passthru]`\n\nPass in one or more file paths to PS1 files that contain functions that meet the above mentioned test syntax.\n\n_NOTE:_ Files will be dot-sources so any code outside of function declarations will also be invoked. Only functions that have the correct signature will be invoked so your file can contain helper functions if desired.\n\n## Output\n\nThe default output is a single result per file.\n\n\n![output](/img/outputexample.png)\n\n\nThe `-Passthru` switch sends `Testing` objects to the pipeline.\nOne object per file.\nEach `Testing` object contains a Result property per test function.\nThere's a lot of room for improvement in this representation.\n\n```powershell\n$results.Results\n\n Pass                                                                  Result\n ----                                                                  ------\n True                                                                       1\nFalse                                      Expected int '1', but got int '2'.\n True                                                                       2\nFalse                               Expected int '1', but got string 'three'.\n True                                                         Bob Man is nice\n True                                                        10 digit is nice\n True                                                      False True is nice\n True                                                                 is nice\nFalse Expected the string 'Bob Man is mean' to match '*nice*' but it did not.\n True                                                         Bob Man is mean\n True                                                                       1\n True                                                                       2\n True                                                         Bob Man is nice\n True                                                        10 digit is nice\n True                                                      False True is nice\n True                                                                 is nice\n True                                                         Bob Man is mean\n ```\n\n The `-Throw` parameter will Throw an exception if any tests fail.\n\n The `-Exit` parameter will exit the process with ExitCode of 0 if all tests pass or an ExitCode equal to the number of failed tests.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdhunt%2Ftesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdhunt%2Ftesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdhunt%2Ftesting/lists"}