I need to use PowerShell to run mvn test
on all test cases individually. I tried to create a Foreach
loop where I recursively pass every test case through mvn test -Dtest
but I keep receiving errors of different kinds, but in every case, the individual tests don't run for some reason.
Get-ChildItem -Path "C:\Users\me\project\src\test" -Filter *.java -Recurse -Name -ErrorAction SilentlyContinue -Force | ForEach-Object {
$file = ($_ -split '\\')[-1]
$name = $file.substring(0,$file.length-5)
mvn test -Dtest=$name
}
However, when I don't pass a variable to mvn test -Dtest
and give it an actual test class name (for example: mvn test -Dtest=AddTest
), the test runs normally. The problems seems to be with $name
getting passed to -Dtest
because I opened this script in VS Code and it said that the $name
variable is never used after being declared even though I use it in the very next line with mvn test -Dtest=$name
.
Here is the main error I've been receiving
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test (default-test) on project: No tests were executed!