I just finished all the learning exercises in the C# track and went on to solve the practice exercises.
All practice exercises that i’ve done so far, have only one test that runs, while all other tests are marked with the “Skip” property.
Is there some command that runs all tests, regardless of the “skip” property, so I don’t have to remove that properties in every exercise? Currently I’m using dotnet test in a PowerShell console inside VS Code.
As far as I can tell, there isn’t. The reason for the skipped tests is to encourage students to solve exercises using a TDD-style approach, where they implement functionality gradually.
In my bash track, there was also an option to run all tests, even if they’re marked “skip”. I guess, for the C# track, I just have to comply with the standards and delete the skip-properties when I want to run the tests.
In the install instructions for the exercism CLI on Linux, there is a script that changes the current working directory to the last downloaded exercise folder. I’ve made something similar for PowerShell and added a function that removes the skip-parameter from a *Tests.cs file and then runs a test. This can be called by “dotnet testall”.
For anyone, who is interested, this is my script file. Just copy the code into the $profile file:
Maybe, that could be added to the install instructions for the exercism CLI on Windows, too.
# catch call to exercism.exe
# this automatically changes the working folder
# when you download a new exercise
function exercism {
Param(
[string]$keyword = ""
)
# run exercism.exe with the given arguments
exercism.exe $keyword @args
# if keyword is "download", extract exercise and track and go to that folder
if ($keyword -eq "download") {
# get exercise
$exercise = (
$args |
where {$_.StartsWith("--exercise=")} |
select -First 1
).ToString().Substring(11)
# get track
$track = (
$args |
where {$_.StartsWith("--track=")} |
select -First 1
).ToString().Substring(8)
# go to that folder
cd $env:USERPROFILE\Exercism\$track\$exercise
}
}
# catch call to dotnet.exe
# adds command "dotnet testall"
# this lets you run all tests, even if they're are marked "skip"
# !!ATTENTION!! : This deletes the "Skip" parameters in the test file
function dotnet {
Param(
[string]$keyword = ""
)
# if keyword = "testall", remove all skip parameters in test file and run test
if ($keyword -eq "testall") {
$testFile = dir -File | where {$_.Name.EndsWith("Tests.cs")} | select -First 1
$content = Get-Content $testFile -Raw
# Removement is done with Regex, so the Skip properties will also be removed,
# if there's a different text attached to them
# !!ATTENTION!! : Doesn't work if a closing bracket is in the Skip-string
$content = [Regex]::Replace($content, '(?i)(?<=\[Fact)\s*\(Skip[^)]*\)', "")
Set-Content -Path $testFile.FullName -Value $content
dotnet.exe test @args
} else {
# pass all other commands to dotnet.exe directly
dotnet.exe $keyword @args
}
}
I didn’t implement it that way, but since the “dotnet test” command is being run from within the PowerShell script, you can easily restore the original test file like this:
# catch call to dotnet.exe
# adds command "dotnet testall"
# this lets you run all tests, even if they're are marked "skip"
function dotnet {
Param(
[string]$keyword = ""
)
# if keyword = "testall", remove all skip parameters in test file and run test
if ($keyword -eq "testall") {
$testFile = dir -File | where {$_.Name.EndsWith("Tests.cs")} | select -First 1
$originalContent = Get-Content $testFile -Raw
# Removement is done with Regex, so the Skip properties will also be removed,
# if there's a different text attached to them
# !!ATTENTION!! : Doesn't work if a closing bracket is in the Skip-string
$skipFreeContent = [Regex]::Replace($originalContent, '(?i)(?<=\[Fact)\s*\(Skip[^)]*\)', "")
# run "dotnet test" with the skip free file, then restore the original contents
Set-Content -Path $testFile.FullName -Value $skipFreeContent
try {
dotnet.exe test @args
} finally {
Set-Content -Path $testFile.FullName -Value $originalContent
}
} else {
# pass all other commands to dotnet.exe directly
dotnet.exe $keyword @args
}
}