Visual Studio+ReSharper运行单元测试报错:测试用例对象缺失及相关问题
Let’s walk through the most effective fixes for the frustrating issues you’re facing—missing test cases, skipped tests, "Inconclusive: Test not run" messages, and that grey eye icon in ReSharper that won’t let you run tests.
Step 1: Clean and Rebuild Your Entire Solution
The error message explicitly calls out rebuilding, so let’s do this thoroughly:
- Close any active test sessions in both ReSharper and Test Explorer first.
- Go to
Build > Clean Solutionin Visual Studio to wipe old binaries. - Once cleaning finishes, run
Build > Rebuild Solution(not just regular Build—Rebuild ensures every project is compiled from scratch). - After rebuilding, try launching your tests again via ReSharper’s test runner.
Step 2: Reset ReSharper’s Caches
Corrupted caches are a common culprit for test detection issues:
- Open ReSharper’s settings: Go to
Extensions > ReSharper > Options. - Navigate to
Environment > General. - Click the
Clear Cachesbutton, then restart Visual Studio when prompted. - Let ReSharper finish indexing your solution fully (wait for the progress bar in the bottom right to disappear), then check if the missing tests reappear.
Step 3: Fix Test Explorer Sync Problems
If Test Explorer is missing 200+ tests, it’s likely out of sync with your solution:
- Click the
Refreshbutton (circular arrow icon) at the top of Test Explorer to force a rescan. - Try toggling the processor architecture: Go to
Test > Test Settings > Default Processor Architectureand switch betweenx86andx64—some test frameworks are tied to specific architectures. - Check if any test projects are excluded from the build: Right-click the test project in Solution Explorer >
Properties> UnderConfiguration Properties > Configuration, make sureBuildis checked.
Step 4: Double-Check Test Class/Method Attributes
Sometimes tests get skipped or undetected due to missing or incorrect attributes:
- Verify your test classes have the right attribute:
[TestClass]for MSTest,[TestFixture]for NUnit, orpublic class(no attribute needed for xUnit, but ensure it’s a public class). - Confirm each test method uses the correct marker:
[TestMethod](MSTest),[Test](NUnit),[Fact]/[Theory](xUnit). - Watch for typos—even a missing bracket or misspelled attribute can make tests invisible to runners.
Step 5: Repair Your Visual Studio Installation
If all else fails, a corrupted VS component might be the issue:
- Open the Visual Studio Installer.
- Select your installed VS version, click
Modify. - Click the
Moredropdown and chooseRepair. - Let the repair process run (it might take a while), restart your machine, then test again.
Step 6: Toggle ReSharper’s Test Runner Integration
Occasionally, toggling the integration resets glitches:
- Go to
Extensions > ReSharper > Options > Tools > Unit Testing. - Uncheck
Enable Unit Testing Support, clickApply, then recheck it and apply again. - Restart Visual Studio and try running tests once more.
内容的提问来源于stack exchange,提问作者goku_da_master

