# Retry flaky tests with dotnet test and PowerShell

DevFeed: [Retry flaky tests with dotnet test and PowerShell](<https://devfeed.tech/articles/retry-flaky-tests-with-dotnet-test-and-powershell-20782.md>)

Original publisher: [Read original article](<https://conductofcode.io/post/retry-flaky-tests-with-dotnet-test-and-powershell/>)

Author: {"twitter"=\>"hlaueriksson"}

Published: 2023-03-26T19:00:00Z

Content type: tutorial

Language: en

Sources: [Henrik Lau Eriksson](<https://devfeed.tech/sources/henrik-lau-eriksson.md>)

Topics: [Test automation](<https://devfeed.tech/topics/test-automation.md>), [PowerShell](<https://devfeed.tech/topics/powershell.md>), [Selenium](<https://devfeed.tech/topics/selenium.md>), [mstest](<https://devfeed.tech/topics/mstest.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [cli](<https://devfeed.tech/tags/cli.md>), [dotnet](<https://devfeed.tech/tags/dotnet.md>), [flaky](<https://devfeed.tech/tags/flaky.md>), [flaky-tests](<https://devfeed.tech/tags/flaky-tests.md>), [mstest](<https://devfeed.tech/tags/mstest.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [powershell](<https://devfeed.tech/tags/powershell.md>), [retries](<https://devfeed.tech/tags/retries.md>), [retry](<https://devfeed.tech/tags/retry.md>), [script](<https://devfeed.tech/tags/script.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [xunit](<https://devfeed.tech/tags/xunit.md>)

## AI overview

The PowerShell `test.ps1` script runs `dotnet test`, reads failed tests from the TRX result file, and reruns those tests up to a configured retry count. It can pass the current retry iteration to the test framework, filter selected tests, and treat a configured percentage of passed tests as success. It returns exit code 0 when tests pass or meet that threshold; otherwise, it returns the number of failed tests. The excerpt says the author showcases NUnit, MSTest, and xUnit integrations, but cuts off during the xUnit details. Parameter defaults, ranges, and sample commands are omitted.

## Source excerpt

Introducing test.ps1, a script for running flaky tests - Keeps track of failing tests and retries them - Notifies the test framework of the current retry iteration - Makes it possible to accept a certain percentage of failing tests - Outputs the test result in a coherent way