How can I see the results of my Unit Tests in VS2017? - visual-studio

I'm running unit tests on my GetModelAsync() and CreateModelAsync() methods in VS17. I then run Assert.Equal checks on the model fields to ensure they match the expected values.
I want to be able to see the final state of my models, which will help me determine why a test is failing or allow me to manually check my models. I'm thinking something similar to tracking variables in the debugger would make sense, although I don't want to actually run the debugger.
Is there a way to do this?

You can write to the console in your tests and it will show up in Test Explorer. You may want to serialize complex objects to JSON first before doing this. For example:
Console.WriteLine(JsonConvert.SerializeObject(myObject));
Note, for Visual Studio's built in test runner, you have to go through a few steps to see the console output. In the Test Explorer window, click the name of your test, then in the results panel click the Output link, which will open a separate window to show the console output. It's all very unintuitive.

Related

Goland: run arbitrary code quality tool, get clickable results

I have an (in-house) code quality tool that produces results like this, when run from the shell:
fooer/quxxer_bulk_stuff.go:40:16: rhubarb rhubarb...
fooer/quxxer_load.go:22:16: rhubarb rhubarb...
fooer/quxxer_load.go:78:16: rhubarb rhubarb...
How do I configure Goland so that I can run the tool on demand (i.e. not a File Watcher) and have the results appear in a run window? Also, I want to be able to click on a line in the results and jump to the referenced file and line, so I can review/fix the problem.
(Goland version 2019.1, Build #GO-191.6183.86)
You can configure it as an external tool in Settings | External Tools. To get clickable results, define an output filter ($FILE_PATH$:$LINE$:$COLUMN$:.* should work for your case). See the documentation for more information.

Use a console window when debugging unit-tests in Visual Studio

When I debug a unit-test with Visual Studio 2017, all the console output is logged and I can examine it by clicking the "Output"-link in the result box of the unit-test (I'm using the built-in Test-Explorer).
However, since I do log a lot to console at runtime which is even color coded so important stuff is more visible, I can't see this color coded output using the "Output"-link, because it's just plain black text on white background.
Is it possible that Visual Studio shows all the output directly in a console window when debugging the tests so I see the output as I would see it when actually running the application outside of a test?
You cannot (or it is very tricky at least) open a console window from a unit test - I've tried with the top 2 answers from the following post, and they didn't work: Show Console in Windows Application?
You can make the Debug.Write... methods write to the Console when you are running/debugging the application itself (not the unit tests) with this code, though:
ConsoleTraceListener listener = new ConsoleTraceListener();
Debug.Listeners.Add(listener);
Any calls to Debug.Write... methods after this code will also output to the console.
Standard output is the only way to display the test output, when we use some output method in our test like Debug.WriteLine(); Console.WriteLine(); etc.
I also tried to change the font of the test output but it seems there is no that option is VS 2017, even someone though someone mentioned this before:
Is there a way to change the Font used in the VS2012 Test Output Window?
Similar case discussed in this thread, even some reply claimed that we could manually launch the console window, but they are 100% sure about it.
If you really need change the font or the color of the test output, in Visual Studio you go to Help -> Send feedback to VS developing team to provider your suggestion .

Is there any way to add/customize in VSTF the Test Runs colums/information?

As a test engineer we always find the lack of info in the Test Runs tab too confusing and useless when it should be one of the most important tab in order to know which test runs are related to which tests builds, test plans, creators, etc
However I can´t find a way to add more columns or info like in the test plan tab. Is there any way to fix this?
No, you can’t add additional columns to test run in Test>Runs tab, you need to check those information in the summary of a test. (Double click a test run> Test results> double click a test)
There is a user voice that you can vote: Additional columns for test run in test > Runs tab

How do I see output from UnitTests in VS2013?

I'm using XUnit, and in both the Visual Studio Test Explorer window and the Resharper Unit Test runner window, I'm no longer seeing the "output" hyperlink that would show the contents of WriteLine commands.
Is there a setting in the IDE that I need to change?
This is a change in xunit2. It no longer captures output from Console.WriteLine, etc. This is because it now runs tests in parallel, in multiple threads, and there's no way of knowing what test the output comes from. It is still possible to capture output, but you need to use xunit's ITestOutputHelper in order to do so. See the xunit docs for more details.

No Coverage Data for Tests in Current Context

I'm using Visual Studio 2010 SP1. When I run "All Tests in Solution", I get code coverage results to show up just fine. However, when I run a subset of tests using "Tests in Current Context", I only see "Cannot find any coverage data (.coverage or .coveragexml) files. Check test run details for possible errors."
A Google search shows that others do get code coverage results when running a subset of tests. Is there a configuration I'm missing somewhere?
I think I figured out the reason for this, but it still doesn't make complete sense. If I run the tests in the current context by going to "Test -> Debug -> Tests in Current Context", it doesn't work (code coverage is not generated). However, if I do "Test -> Run -> Tests in Current Context", then it works. So far so good, it kind of makes sense that it would only work when not in Debug mode.
But the strange part is if I use the keyboard shortcut for "Test -> Run -> Tests in Current Context" (Ctrl-R, T), it does not work. So I have to run it from the menu instead of using the keyboard shortcut, otherwise it says no code coverage was generated.

Resources