如何停止NUnit TestRunner?及NUnit测试异常问题求助
Hey there, let's work through this flaky NUnit test behavior you're dealing with in VS 2017 Enterprise. I’ve run into similar unpredictable test issues with older NUnit versions and TestDriven.Net combinations, so here are targeted fixes to try out:
Stale cached assemblies or state from NUnit/TestDriven.Net is a super common culprit for weird test behavior. Do this:
- Close VS 2017 entirely, then delete the
binandobjfolders across all projects in your solution to clear compiled outputs. - Navigate to
%USERPROFILE%\AppData\Local\NUnitand delete everything inside this directory to purge NUnit's cached data. - Restart VS, rebuild your entire solution from scratch, then re-run your tests.
You’re using TestDriven.Net V4.1-Alpha—alpha builds often have unpatched bugs that clash with specific NUnit versions. Try:
- Downgrading to a stable release of TestDriven.Net (like V3.0.x) that explicitly supports NUnit 3.x and .NET 4.0.
- Or upgrading to the latest stable TestDriven.Net version to see if compatibility with NUnit 3.9/3.10 has been fixed.
TestDriven.Net isn’t your only option—VS 2017 has native support for NUnit tests. Let’s rule out TestDriven.Net as the issue:
- Install the NUnit 3 Test Adapter via VS’s Extension Manager (search for it in the Extensions menu).
- Disable or uninstall TestDrivenNet temporarily, then use VS’s Test Explorer to run your tests. If the unpredictability goes away, you know the problem lies with TestDrivenNet.
Even "simple" tests can fail if they rely on static variables, singletons, or shared external resources (like files, database connections) that don’t get reset between runs. Make sure:
- Each test uses
[SetUp]and[TearDown]attributes to reset static state or release shared resources before/after execution. - Tests are completely independent—no mutable objects or state should carry over from one test to the next.
Old patches can cause compatibility glitches between VS 2017, .NET 4.0, and test tools:
- Install all available updates for VS 2017 (go to Tools > Get Tools and Features > Updates).
- Make sure your Windows 10 Pro is fully updated—system-level bugs can sometimes trickle up to affect test runtime behavior.
If you can grab specific error messages (from VS’s Output window or NUnit’s logs) when the tests misbehave, that’d help narrow things down even more. But these steps should resolve most of the unpredictable behavior you’re seeing.
内容的提问来源于stack exchange,提问作者Alex Konnen

