VS2013的NUnit v2.x测试无法在VS2017测试资源管理器中显示
Hey there, I’ve dealt with this exact NUnit version compatibility snag before— let’s walk through the fixes that worked for me and other devs:
1. Fix Version Compatibility Between NUnit and Test Adapter
NUnit 3’s test adapter (NUnit3TestAdapter) doesn’t fully support NUnit 2.x test syntax out of the box. You’ve got two solid paths here:
Option A: Upgrade Tests to NUnit 3 (Recommended for Long-Term Support)
If you’re open to updating your test code:
- Uninstall the current
NUnitv3.10.1 andNUnit3TestAdapterv3.10.0 NuGet packages from your test project - Reinstall the latest compatible versions of
NUnitandNUnit3TestAdapter(stick to matching major versions for best results) - Tweak your test code to use NUnit 3 syntax:
- Swap
[TestFixtureSetUp]with[OneTimeSetUp] - Swap
[TestFixtureTearDown]with[OneTimeTearDown] - Most assertion methods like
Assert.AreEqualare backward compatible, but double-check any niche NUnit 2-specific calls
- Swap
Option B: Stay on NUnit 2.x
If you need to keep the original test code as-is:
- Uninstall
NUnitv3.10.1 andNUnit3TestAdapterentirely - Install the exact NUnit 2.x version used in the original VS2013 project (e.g., v2.6.4) via NuGet
- Install the NUnit Test Adapter (not the 3.x version— look for the package named
NUnitTestAdapter, typically v2.0.0 or later that supports NUnit 2.x)
2. Align Processor Architecture Settings
Your VS2017 default is set to X64, but your test project builds for X86— this mismatch often blocks test discovery:
- Go to the
Testmenu in VS2017 - Select
Test Settings>Default Processor Architecture> choose X86 to match your project’s "Active Solution Platform" setting
3. Clean Up Cached Build Files & Rebuild
Sometimes stale build files cause issues that a basic clean/rebuild misses:
- Delete the
binandobjfolders directly from your test project directory - Restart Visual Studio
- Do a full clean (
Build>Clean Solution) followed by a rebuild (Build>Rebuild Solution)
4. Quick Attribute & Project Check
Even though you mentioned attributes are correct, a quick verify won’t hurt:
- Ensure your test class has the
[TestFixture]attribute (required for NUnit 2; NUnit 3 allows omitting it, but keeping it works) - Confirm each test method is
publicand decorated with[Test] - Make sure your test project is set to Class Library as its output type (right-click project > Properties > Application > Output type)
Start with the version compatibility fix— that’s the most common culprit here. If you work through these steps one by one, your tests should pop up in the Test Explorer in no time!
内容的提问来源于stack exchange,提问作者Andrew

