locked
[C#] [VS2015] VSTest failing because not run as 'Debug' RRS feed

  • Question

  • My app is running fine from the Debugger in VS2015 and can run in Release mode deployed to my PC quite happily.

    However when I attempt to run any Test cases they are all failing because an object can't be initialised properly.

    The code causing the issue is this:

    #if DEBUG
                currentApp = CurrentAppSimulator.LicenseInformation;
    #else
                currentApp = CurrentApp.LicenseInformation;
    #endif

    Note that since moving to Win10 & VS2015 the CurrentApp/Simulator objects appear to 'silently' fail; that is to say there are no errors thrown when they are hit incorrectly (using CurrentApp in Debug mode for example), instead they appear to 'break' the current method and return.
    In this instance that is causing my parent object to fail to initialise fully, which in turn is causing my test cases to fail.

    Is there a way to configure the test runner to pass the 'DEBUG' property to the runtime?

    Any suggestions appreciated.



    Friday, August 14, 2015 3:45 PM

All replies

  • So I moved the license management component out of the constructor of this object to see if I could get it to initialise properly, but this is just moved the issue seemingly.

    Take this for example:

    Value does not fall within the expected range.

    at Windows.UI.Notifications.TileUpdater.EnableNotificationQueue(Boolean enable)

    The code reference looks (as you would expect):

    tileUpdater.EnableNotificationQueue(true);

    This again causes the containing ctor to bomb out:

    System.TypeInitializationException: The type initializer for 'Project.Services.ServiceLocator' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.

    The frustrating thing is that this is ONLY happening when I run the Tests in Visual Studio.

    Friday, August 14, 2015 4:44 PM
  • Hi MrChris,

    I've moved this case to Unit Testing forum for you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 17, 2015 9:52 AM
  • Hi MrChris2000,

    It seems that the real issue is not the VS unit test issue, it is related to the NUnit test.

    Just to make this issue clearly, do you install the NUnit Test Adapter extension tool in your VS IDE?

    https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d

    #if DEBUG
                currentApp
    = CurrentAppSimulator.LicenseInformation;
    #else
                currentApp
    = CurrentApp.LicenseInformation;
    #endif

    Was the code in your Nunit test project or the app you want to test? If you debug your test method in Test Explorer windows, how about the result?

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 18, 2015 6:45 AM
  • Sorry, force of habit, this is using:

    Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

    Not NUnit. I've updated the title accordingly.

    Either way, the code where the errors are occurring is within the application under test.

    The test case is creating an instance of an object from the application model, during the ctor phase this object then instantiates a number of other objects to support itself and it is in these down stream objects that this error is being generated.

    Leading to a xxx.ctor, xxx..ctor set of errors. As I say though my biggest head scratch here is that this code works fine if I run the main application. That would imply it is an instantiation ordering issue to me, but the test is following the same steps as the app.

    Very odd.

    Tuesday, August 18, 2015 8:17 AM
  • Hi MrChris2000,

    Thanks for your friendly response.

    >>Leading to a xxx.ctor, xxx..ctor set of errors. As I say though my biggest head scratch here is that this code works fine if I run the main application.

    Could you share us the detailed error messages? Maybe a screen shot would be better.

    If you add breakpoints in your test project, and then debug it one step by one step, whether it is related to the specific code in your test project which called certain method in your app?

    Please also enable the options in Exception windows under Debug menu, so it would stop when it met an exception.

    Since you said that your app worked well, how did you run your app, Start without debugging(Ctrl+F5) or Start debugging F5?

    Could you share us the main code in your test project? Maybe you could share us a simple sample with one drive, so we could really test it in our side.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 19, 2015 1:54 AM