You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jenkins中通过PowerShell跳过指定NUnit测试?

How to Skip/Ignore NUnit Tests via PowerShell

Absolutely! You can skip specific NUnit tests directly through PowerShell by leveraging NUnit console's built-in filtering parameters—no need to modify your test code (unless you want to use categorization for easier long-term management). Here are a few practical, actionable ways to do this:

If you want a reusable way to mark tests for skipping, first tag the tests you want to exclude with a [Category] attribute in your test code:

[Test, Category("SkipOnJenkins")]
public void MyTestToSkip()
{
    // Your test logic here
}

Then update your PowerShell script's Invoke-Expression line to add the /exclude parameter, specifying the category name you created:

$tests = ''
Get-ChildItem -path "." -Recurse -Include "*Test*.dll" | Where-Object {$_.DirectoryName -Match ".*\\bin\\Debug"} | foreach {$tests += ($_.toString() -ireplace ([regex]::Escape($env:WORKSPACE) + '\\'), ' ')}
$env:COMPLUS_Version='v4.0.0000'
# Add /exclude to skip tests in the "SkipOnJenkins" category
Invoke-Expression "C:\Jenkins\workspace\APP\Build\NUnitForms\lib\nunit\nunit-console-x86.exe $tests /result:nunit-result.xml /exclude:SkipOnJenkins"

This will automatically exclude all tests tagged with that category every time you run the script.

2. Skip Tests by Name (Temporary/Ad-Hoc Skipping)

If you need to skip specific tests without touching your test code, use NUnit's name filtering with the /exclude parameter. You can use exact names or wildcard/regex patterns:

  • Skip a single test by exact name: /exclude:Name=MySpecificTestToSkip
  • Skip all tests containing a keyword (e.g., "Slow"): /exclude:Name~Slow

Here's how your modified PowerShell command would look for skipping slow tests:

Invoke-Expression "C:\Jenkins\workspace\APP\Build\NUnitForms\lib\nunit\nunit-console-x86.exe $tests /result:nunit-result.xml /exclude:Name~Slow"

3. Note for NUnit 3+ Users

If you're using a newer NUnit 3 console runner (instead of the NUnit 2.x nunit-console-x86.exe), the parameter syntax changes slightly—use --where instead of /exclude:

# Skip tests in "SkipOnJenkins" category
Invoke-Expression "C:\Jenkins\workspace\APP\Build\NUnitForms\lib\nunit\nunit3-console.exe $tests --result:nunit-result.xml --where 'cat != SkipOnJenkins'"
# Skip tests with name containing "Slow"
Invoke-Expression "C:\Jenkins\workspace\APP\Build\NUnitForms\lib\nunit\nunit3-console.exe $tests --result:nunit-result.xml --where 'name !~ Slow'"

内容的提问来源于stack exchange,提问作者Gopinath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:08:07