Created
December 4, 2025 08:30
-
-
Save nohwnd/3a05153f11b1a1eb6c3793311c25292d to your computer and use it in GitHub Desktop.
Generate tests for mstest / xunit / nunit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # I am putting this code into my powershell profile. | |
| function Get-MSTestTests { | |
| param ( | |
| $classes = 100, | |
| $methods = 100 | |
| ) | |
| Get-Tests -classes $classes -methods $methods -header "namespace mstest256;" -start @" | |
| [TestClass] | |
| public sealed class Test<i> | |
| { | |
| "@ -end "}" -middle @" | |
| [TestMethod] | |
| public void TestMethod<y>() | |
| { | |
| } | |
| "@ | |
| } | |
| function Get-XunitTests { | |
| param ( | |
| $classes = 100, | |
| $methods = 100 | |
| ) | |
| Get-Tests -classes $classes -methods $methods -header "namespace mstest256;" -start @" | |
| public sealed class Test<i> | |
| { | |
| "@ -end "}" -middle @" | |
| [Fact] | |
| public void TestMethod<y>() | |
| { | |
| } | |
| "@ | |
| } | |
| function Get-NunitTests { | |
| param ( | |
| $classes = 100, | |
| $methods = 100 | |
| ) | |
| Get-Tests -classes $classes -methods $methods -header "namespace mstest256;" -start @" | |
| public sealed class Test<i> | |
| { | |
| "@ -end "}" -middle @" | |
| [Test] | |
| public void TestMethod<y>() | |
| { | |
| } | |
| "@ | |
| } | |
| function Get-Tests { | |
| param ( | |
| $classes = 100, | |
| $methods = 100, | |
| $header, | |
| $start, | |
| $end, | |
| $middle | |
| ) | |
| # $header = "namespace mstest265;"; | |
| # $start = "[TestClass] | |
| # public sealed class Test<i> | |
| # {" | |
| # $end = "}" | |
| # $middle = " | |
| # [TestMethod] | |
| # // [ExpectedException(typeof(InvalidOperationException))] | |
| # public void TestMethod<y>() | |
| # { | |
| # // throw new InvalidOperationException(); | |
| # }" | |
| @" | |
| $header | |
| $(foreach ($i in 1..$classes) { | |
| "$($start -replace "<i>", $i) | |
| $(foreach ($y in 1..$methods) { | |
| $middle -replace "<i>", $i -replace "<y>", $y | |
| }) | |
| $($end -replace "<i>", $i)" | |
| }) | |
| "@ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment