How to show only method name in Test Explorer in VS 2017 (using xUnit for .NET Core) - unit-testing

I know there is this question:
How can XUnit be configured to show just the method name in the Visual Studio 2015 Test Explorer?
I tried both the solution using XML and the JSON file but the name in Text Explorer Window is still the full name with the class. I want to display the method name only as its hard to read the fully qualified names.
Its stated on this site that you can configure using XML
Configuring xUnit.net with XML
but I can't make the effect I'm expecting happen. I've restarted VS 2017 after adding an app.config file in the test project, but still nothing. Is it different for VS 2017?

I had the same issue. I'm doing a project in VS2017 using .NET Standard and solved it by following these steps:
In your tests project, create a file named xunit.runner.json
Add the following to the file: { "methodDisplay" : "method" }
In the Solution Explorer, right-click on xunit.runner.json and select "Properties". Set Copy to Output Directory to "Copy Always".
Taken from this comment.

W. Hampson answer is perfect, but just to inform about other possibility - use DisplayName attribute.
[Fact(DisplayName = "Just simple check")]
public void Check()
{
Assert.NotNull(_operation);
}

Related

Visual Studio Code's "Run Test | Debug Test" option missing from unit tests

I used to see "Run Test | Debug Test" links top of every test function in VS Code for Go. But they are missing now. How can I re-enable them?
This picture shows what I am talking about:
Check your options to confirm that the Go test explorer is enabled:
Preferences > Settings > User Settings > find "go test enable code lens"
Taken directly from the go.dev doc for the testing package
To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions as described here. Put the file in the same package as the one being tested.
Please ensure that your test file name ends in _test.go, and that the function you're trying to test starts with Test (like it does in your snippet).
Had the same issue today. In my case opening the Command Palette (Ctrl+Shift+P) and running "OmniSharp: Restart OmniSharp" fixed it.
Same thing here - simply closed down VS Code and opened it back up again... they all appeared once more.
This happened to me, though I was writing Javascript (not Go).
To fix that, I need to make sure the Es6 import & export statements are correct (-- correctly importing the correct item from the correct file path),, -- for this current test js file & relevant imported js files (or even all files in current project).
(Then you must save the test js file to refresh it.)
The Test Explorer's Output panel may(?<) throw an Error to indicate that.
I have this situation when there are many folders in the project I opened in VScode. But these options appear only when I open the folder containing the script I want to run the test in in a new window in VSCode. I don't know why, it's weird.

How unit test logic in xamarin forms with a separated console project with F#?

I have a complete new/empty project with xamarin.forms 2.3.4 with F#.
I have a shared project, with a extra module for the logic:
module Db
let openDb() =
printf "Hello"
Then I create a console project, reference the shared project & related libraries, and try to run it:
open Db
[<EntryPoint>]
let main argv =
Db.openDb()
0
Now I getting this error:
../Test/Tests.fs(6,6): Error FS0039: The namespace or module 'Db' is not defined. Maybe you want one of the following: XDB (FS0039) (Test)
I not getting any other error. I try both with xamarin & Visual Studio Mac; and also creating a UI test project (however, I only care for logic testing).
This is an empty form project without anything else.
P.D: I make it to work if a just delete the reference to the shared project and link manually the files. However, I wonder if is possible to cover this scenario...
Is there an EntryPoint file under the file that defines the module?
The location of the file can be changed with alt +up arrow and alt +down arrow(win + visual studio) or Db.fs(in Solution Explorer) is right click -> Move up
F# is readed file from up to down.(See "Projects and Solutions" on this site )
It Maybe that(win10 ,visual studio 2017)
Db.fs is difine module. There is an entry EntryPoint program.fs.
Also, if the namespace and the module name are the same, an error will occur. module name for this project is Bar.

Don't display class name in Visual Studio Test Explorer

I am using Xunit in my vs project. In my Test explorer, I see this:
Fully.Qualified.Namespace.ClassName.TestName1
Fully.Qualified.Namespace.ClassName.TestName2
etc.
I would much rather just see this:
TestName1
TestName2
etc.
or even this (2nd best, but still a big improvement):
ClassName.TestName1
ClassName.TestName2
etc.
Is that possible? If so, how?
add a file to the root directory of your test project named xunit.runner.json
with the following content:
{
"methodDisplay": "method"
}

What is the correct syntax to include or exlude test assemblies in Visual Studio Tests with Visual Studio Team Services VSTS

I have 2 test projects in my solution. I want to exclude one of them (with Selenium tests) to be excluded from the Visual Studio Test that is part of the continuous integration cycle.
The name of the generated dll is:
Ta-Tend.UITests.dll
The option "Test assembly" (form the Test Execution Options) is:
*test*.dll; -:\obj**; -***UITest*.dll
Whatever I fill in, the test is executed, while I need it to be excluded.
I cannot find anywhere the complete syntax definition for this field. Just parts of it, but they don't work.
Using this code instead:
*test*.dll;-:**\obj\**;-:**\*UITest*.dll
If Ta-Tend.UITests.dll file is in the subfolder, using
**\*test*.dll;-:**\obj\**;-:**\*UITest*.dll

How to specify the location for the unit test results in VS 2010?

I use VS2010 for unit testing. Does anyone know how to specify the location of where VS 2010 put its TestResults? By default it put a TestResults folder in the solution folder, I'd like to move it out somewhere else.
Thanks,
Ray.
Currently, this is not possible to control from within the IDE, see http://social.msdn.microsoft.com/Forums/en/vststest/thread/4ff650e1-a99a-4bd4-8311-6007f2a6e16e.
However, if you can use MSTEST.EXE from the commandline, it will use the current folder to generate the TestResults folder in.
Update:
Found this in http://blogs.msdn.com/b/vstsqualitytools/archive/2010/10/24/test-agent-test-controller-and-mstest-faq.aspx:
How to customize the default deployment directory?
You can change the default deployment folder by editing the test settings file in the XML editor:
<Deployment userDeploymentRoot="C:\TestResults" useDefaultDeploymentRoot ="false" />
Note that ,if the test settings is modified by XML edit (instead of using the default editor) VS need to be closed and reopened ( since the editing is done in XML , the changes will not be updated in the loaded settings.)
Best regards,
Marco Kroonwijk
MSTest.exe will generate results in the current folder as kroonwijk states, but you can override that with the /resultsfile command line switch by specifying the output filename in a different folder, it will also deploy a subfolder with the test files to the same location.
For example "/resultsfile:c:\TestResults\mstestreport.trx" will override the default deployment folder and also override anything that is in the <deployment> tag in the settings file.