Visual Studio 2017 UWP单元测试创建及Test Explorer问题咨询
Hey there, let's work through this Test Explorer issue you're hitting with your UWP unit test project. First, let's recap your setup to make sure we're aligned:
- Visual Studio Version: 2017 15.6.1
- Project Type: Unit Test Project (Universal Windows)
- Target/Minimum Versions:
- Target: Fall Creators Update (10.0; Build 16299)
- Minimum: November Update (10.0; Build 10586)
- Test Code (UnitTest1.cs):
[TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { Assert.AreEqual(0, 0); } [TestMethod] public void TestMethod2() { Assert.AreEqual(0, 0); } }
Now let's go through common fixes for Test Explorer not behaving as expected (like tests not showing up, failing to run, etc.):
First, do a full rebuild of your solution
Sometimes partial builds leave behind stale artifacts. Go toBuild > Rebuild Solutionand wait for it to complete. Then check Test Explorer again—often this fixes missing tests or unexpected errors.Verify the UWP Test Adapter is installed and enabled
UWP tests rely on the correct test adapter. Go toTools > Extensions and Updates, search for "Universal Windows Platform Test Adapter" under the "Installed" tab. If it's missing, install it from the "Online" tab. Also, make sure it's enabled in the adapter settings (right-click in Test Explorer > Settings, ensure the UWP adapter is checked).Check if your target/minimum version combination is compatible with VS 2017 15.6.1
VS 2017 15.6.1 has specific support for UWP SDK versions. While your target (16299) and minimum (10586) should be compatible, double-check that you have the Windows 10 SDK (16299) installed. Go toTools > Get Tools and Features, select the "Individual components" tab, and confirm the SDK is listed under "SDKs, libraries, and frameworks".Clean and reset your solution's build output
Delete thebinandobjfolders for both your main app project and the unit test project. Then restart Visual Studio, rebuild the solution, and try running the tests again. This clears out any corrupted build files that might be interfering.Reset Test Explorer's state
If Test Explorer is showing odd behavior (like empty lists or stuck runs), you can reset it: right-click inside Test Explorer >Clear Test Results, then click theRefreshbutton (circular arrow icon) to re-discover tests.Ensure your test class and methods are properly attributed
Your code looks correct with[TestClass]and[TestMethod]attributes, but double-check that you have the necessary using directives at the top ofUnitTest1.cs:using Microsoft.VisualStudio.TestTools.UnitTesting;Without this, the attributes won't be recognized, and tests won't show up.
If none of these steps resolve your issue, feel free to share more details about exactly what's happening in Test Explorer (e.g., tests not appearing, error messages when running, etc.) and we can dig deeper.
内容的提问来源于stack exchange,提问作者user3239349

