none
Why don't any unit test projects appear and act like unit test projects? RRS feed

  • Question

  • I'm working on a UWP app, so last week I created a Universal Windows unit test project. It never works or runs as a unit test project. Instead, VS 2019 seems to think its some sort of, I don't know, maybe a library project? Anyway, I cannot run any of the tests in it, nor debug any of the tests in it. Since it doesn't work as a unit test project, I stopped writing unit tests. After all, what's the point of writing unit tests if the framework doesn't treat them as unit tests? Here's the only code I wrote, referencing the code (SalaryConvUS) that I'm trying to test:

    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using SalaryConv;
    
    namespace SalaryConvTest
    {
        [TestClass]
        public class SalaryConvTests
        {
            [TestMethod]
            public void WeeklyTest()
            {
                //assign
                var o = new SalaryConvUS();
    
                //act
                o.Hourly = 20.0M;
                var ret = o.Weekly;
    
                //assert
                Assert.AreEqual(800M, ret);
            }
        }
    }
    

    Yesterday, I decided I would try just testing another unit test project, just in case the first one was corrupted in some way. So, I created another Universal Windows unit test project. In this case I didn't even reference the code I'm trying to test. I decided just to see if this new unit test project would behave like a unit test project. Whether or not I could run it, debug it, see if VS 2019 identifies it as a unit test project with unit tests in it. That failed, too!! VS 2019 doesn't run anything when I try running all unit tests. It's just ignored, spins a little and then stops, thinking it's over. Nothing tested. Here's the code for it:

    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace SalaryConv2Test
    {
        [TestClass]
        public class TestSalaryConv
        {
            [TestMethod]
            public void TestHourly()
            {
                //assign
                int i = 0;
    
    
                //act
                i++;
    
    
                //assert
                Assert.AreEqual(1, i);
            }
        }
    }
    

    That code is not rocket science, but it IS a unit test. So, why in heck doesn't VS 2019 treat it like a unit test and run TestHourly when I tell it to Run All Test, or run the selected test, or debug the selected test? What in heck is wrong with VS 2019?????????????????

    I'm using VS 2019 Community Edition.


    Rod

    Saturday, January 4, 2020 3:26 PM

All replies

  • Hi Rod,

    Thank you for posting here.

    I followed your codes and tested in my side, actually, test UWP costs some time but “unit test” still runs and finishes testing. (VS 2019 Community)

    Do you install some third-party extensions or plugins? You could start VS in Safe Mode by opening “Developer Command Prompt for VS 2019” and enter “devenv /safemode” to avoid the impact from other extensions.

    Not sure if there is something wrong with VS, maybe you could try to repair/update it(Visual Studio Installer -> find VS 2019 Community -> More/update -> Repair).

    Hope this could help you and any feedback will be expected.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 6, 2020 4:19 AM
  • Hi Tianyu,

    Thank you for your response. I'm sorry I haven't seen it earlier.

    Thinking about it, yes I have installed a third party extension. I'm using Template 10. Now I'm wondering if that has anything to do with it? I use VS 2019 at work, although I do regular WPF and ASP.NET MVC apps there, not UWP. 

    I'm sorry, I've got to stop now so I can catch a bus. Will get back to this later.


    Rod

    Thursday, January 9, 2020 12:00 AM
  • Hi Tianyu,

    I'm at home and can test running VS 2019 in safe mode. I have brought it up, but now a different issue presents itself. Here's a screenshot of my Solution Explorer:

    My solution explorer

    What does it mean, "(needs migration)"? It's giving me that on all projects, including the two UWP unit test projects, SalaryConv2Test and SalaryConvTest. I don't know why they suddenly show up when running VS 2019 in safe mode. And I don't know what I should do about them.


    Rod


    • Edited by Doctor-Who Thursday, January 9, 2020 4:22 AM
    Thursday, January 9, 2020 4:19 AM
  • Hi Rod,

    Thank you for your feedback.

    It seems some components also be forbidden to load under safe mode, another workaround is that you could try to disable/stop the third-party extensions temporarily to troubleshoot.

    BTW, I also try to test in VS 2019 Community 16.4.2 version(latest version)(newly installed and only installed “Universal Windows Platform development”) this time and the test runs normally. I’m afraid, this issue seems affected by third-party extensions.

    Hope this could help you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 9, 2020 7:58 AM
  • I think I've found the problem. I have an extension named XAML Styler installed. It is a third party extension by someone named Xavalon. I've disabled it and now VS 2019 recognizes my unit tests. I'm going to uninstall it next and see what happens...

    ... that extension is not uninstalling smoothly. It's been 5 minutes and its still uninstalling. I'm going to leave it alone and get back to you when this is finished. Shutting everything else off, to let the VSIX Installer run.

    ...After I closed everything except for the VS Installer, then the VS Installer started right up and finished removing XAML Styler. I thought I'd try to find something else to remove and saw the "Xamarin Templates [Experimental]". I want to do some mobile development, so I installed Xamarin. I thought maybe removing that extension might help, but when I tried VS 2019 brought up the VS Installer again and it looked like it was going to remove all of Xamarin. I don't want that.

    I'm going to try creating a new, blank UWP app and add a UWP unit test. Then try putting in some silly code to see if the unit test works. More later.


    Rod


    • Edited by Doctor-Who Friday, January 10, 2020 2:24 AM
    Friday, January 10, 2020 2:09 AM
  • Hi Tianyu,

    I've finished creating an empty UWP project. Then I added a UWP unit test project to the solution. I added a unit test similar to the original post (just checking to see if Assert.AreEqual(1 , i) is true, which it should be.) Unfortunately I'm back to the problem I had when with the original post. I even run Vs 2019 in safemode, it doesn't recognize the unit test. And when I have it open while running VS 2019 in safe mode I have that "(needs migration)' message after every project.

    Like I said earlier I've uninstalled XAML Styler, which is the only 3rd party extension I had. The only extensions still in VS 2019 is all from Microsoft.

    The odd thing is that I can write unit tests for other project types and they work fine. For me, at this point, it seems like its UWP projects I cannot use unit tests with.

    The extensions I have installed and enabled, are:

    • Live Share
    • Azure Data Lake and Stream Analystics Tools
    • Xamarin.Apple SDK
    • Xamarin.Android SDK
    • Xamarin Templates
    • Developer Analytics Tools
    • Developer Analytics Tools  (yes, its there twice; no, I've no idea why)
    • Cloud Explorer for VS 2019 Preview
    • Visual Studio IntelliCode
    • Microsoft Library Manager
    • Visual Studio Extensions for Windows Library for JavaScript
    • Microsoft Advertising Framework

    At this point what do you recommend that I do?


    Rod

    Friday, January 10, 2020 3:28 AM
  • Hi Rod,

    Thank you for your feedback.

    Follow your description, I installed these extensions one by one to test and after installing all of them, the Unit Test(UWP) still works.

    After considering more, I checked if there are some different configurations between UWP and others, and one thing hit me, I may ignore it – the developer features. This setting is under Settings -> For developers, and you need to choose “Developer mode” to make it work. (Maybe you have chosen this option)

    I really hope it could work for you this time.

    Any feedback will be expected.

    Sincerely,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.





    Friday, January 10, 2020 7:03 AM
  • Hi Tianyu,

    I already have Developer Mode set in Windows 10 Settings. :(


    Rod

    Saturday, January 11, 2020 1:22 PM
  • Hi Rod,

    Thank you for your feedback.

    Maybe reset settings could repair this, another two workarounds to reset VS IDE/VS environment:

    #1. Start “Developer Command Prompt for VS 2019” and enter devenv /ResetSettings to restore VS default settings.

    #2. Start VS -> Tools -> Import and Export Settings… -> Reset all settings -> “No, just reset settings, overwriting my current settings” -> Next -> Finish.

    BTW, if you have an antivirus software on your computer, please stop it temporarily and check if this time the test runs well.

    Any feedback will be expected.

    Sincerely,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 13, 2020 9:58 AM
  • Hi Rod,

    Sorry to bother you.

    Do my suggestions work, and do you have any update?

    I’m sorry, if this issue still persists, I’m afraid reinstall VS maybe helpful. I know nobody wants to reinstall VS and it cost much so you may try this if all “reset”/repair/update didn’t work.

    Any feedback will be expected.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 17, 2020 10:02 AM
  • Hi Tianyu,

    I'm sorry for not responding earlier. 

    I was about to do the devenv /ResetSettings command, when I saw your recomendation of turning off my anti-virus temporarily. I'm using Windows Defender, but don't know how to turn it off temporarily. How do I go about doing that?


    Rod

    Friday, January 17, 2020 2:40 PM
  • Hello Rod,

    Sorry for delay in reply.

    >> but don’t know how to turn it off temporarily.

    ## You could go to Settings|Update & Security|Windows Security|Virus & threat protection|”Virus & threat protection settings”/Manage settings|turn off “Real-time protection” to turn off Windows Defender temporarily.

    ## I saw that you mentioned you just use Windows Defender, actually I use it too and it will not affect the test, except you use some third-party anti-virus software.

    And have you done the devenv /ResetSettings command and does it work this time?

    Looking forward to hearing from you.

    Sincerely,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 20, 2020 8:37 AM
  • Hi Tianyu,

    I'm sorry I haven't replied sooner. My priorities have changed recently. I probably won't be able to pick this up again until after February 21. I hate putting it off, but given my schedule I've just got to work on another project between now and February 21. I'll get back to you after that.


    Rod

    Sunday, January 26, 2020 12:50 AM