nunit3-vs-adapter icon indicating copy to clipboard operation
nunit3-vs-adapter copied to clipboard

Visual Studio 2019 - Console Unit Fails

Open ofthesea-io opened this issue 6 years ago • 10 comments

Hi

I have a unit test that compares two numbers. In VS 2017, this test passes without any issues. I installed VS 2019 and the following exception gets thrown, when running my unit tests:

Message: The handle is invalid at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded) at System.Console.get_CursorTop()

which happens at this point in the code:

boardTop = Console.CursorTop + 1;

However. if I debug the Unit Test, it passes.

NUnit v3.11.0 NUnit 3TestAdapter v3.13.0

*Update

I have tested the units on Visual Studio 2019 for Mac and the test run correctly.

ofthesea-io avatar Apr 03 '19 13:04 ofthesea-io

I can reproduce the problem. That being said, I think that this is a change in Visual Studio and not something that NUnit can affect, but perhaps it is possible using a runsettings file?. I know that MS have made some changes to how VS interacts wrt. console applications in 2019, but I cannot find anything related to testing.

This issue should probably be moved to the nunit3-vs-adapter project, if we can do anything, but I don't have the rights to do this. Ping @OsirisTerje and @jnm2 as they know more about the adapter than I (and also they should have rights to move the issue).

mikkelbu avatar Apr 03 '19 17:04 mikkelbu

Thank you for the update! I wasn't to sure which repo the problem belonged too, until I ran it the tests on my Mac.

ofthesea-io avatar Apr 04 '19 11:04 ofthesea-io

@VisualSanity I can only speak for Windows, but I wouldn't expect to be able to use Console.CursorTop unless there is an actual terminal UI attached to the process (when Console.IsOutputRedirected etc are false). Are you sure this is related to NUnit, or does it happen with MSTest too?

jnm2 avatar Apr 21 '19 16:04 jnm2

@mikkelbu In order to move issues between repos, you must be an admin in both. I'm not an admin in any NUnit repo, so I've never been allowed to use the new GitHub feature. I've submitted feedback to them via email and Twitter that a setting to allow members to move stuff would be helpful.

/cc @rprouse, @OsirisTerje

jnm2 avatar Apr 21 '19 16:04 jnm2

Part of the confusion is that the github feature is locked down more than the old zenhub feature, which I think you could still use if you have it in your browser.

CharliePoole avatar Apr 21 '19 16:04 CharliePoole

Moving to the adapter project. It is annoying that you need to be an admin in both repos ☹️

rprouse avatar Apr 21 '19 18:04 rprouse

@mikkelbu Did you make a repro project ? Can you share it? I'll send it over to the PG and ask them.

OsirisTerje avatar Apr 21 '19 19:04 OsirisTerje

@OsirisTerje I had at some point, but I think I've deleted it again. So I've create a new project https://github.com/mikkelbu/NUnit.CursorTopTest. The test pass in VS2017 both when executing the test normally and when debugging the test. On VS2019 the test fail when executing the test normally, but it still passes when I debug the tests.

Ps. If I clean the repository - using git clean -xdf - then I have to rebuild the solution two times in order to be able to run the test in VS2019 (or using "Clean Solution" in VS). If I don't do this then I get "Run test finished: 0 run" and grayed text in Test Explorer and a white exclamation mark on a blue sign. Pps. My VS2019 is preview 4.3 as I've not had time to update it yet.

mikkelbu avatar Apr 21 '19 20:04 mikkelbu

@mikkelbu I believe this is a Visual Studio issue. We did change some behavior in the console window in Visual Studio 2019. Could you open a bug on https://developercommunity.visualstudio.com/ ? Thank you for including the repro solution! Any details you can include on how this impacts your workflow would be greatly appreciated. (i.e. Let us know if this is a major breaking scenario!)

I am also observing this on my machine, but am not sure of the cause. Filing it on developer community will help route it to the right team.

kendrahavens avatar Apr 25 '19 23:04 kendrahavens

@kendrahavens @OsirisTerje I've created https://developercommunity.visualstudio.com/content/problem/551129/change-in-behaviour-between-vs-2017-and-vs-2019-wh.html, but I've not provided any information about how this impacts my workflow, as the problem was experienced by @VisualSanity, I just helped to diagnose the problem. Perhaps @VisualSanity can provide the information on developercommunity.

mikkelbu avatar Apr 29 '19 17:04 mikkelbu