TFS 2013 build with xUnit and MsTest both - build-process

Does TFS 2013 using (tfvcTemplate.12.xaml) support multiple test runners? We have two unit test projects in our solution (MsTests and XUnit). I would like the build to run xUnit tests as well as MsTests.
Projects:
MySolution.UnitTests (mstests)
MySolution.UnitTests.xUnit (xunit tests)
I have VS2013 installed on the build server.
Looks like MsTests are run fine, but not xUnit. The results show only MsTests and no xUnit tests.
How would I specify xUnit to be also executed?

You just need to add the xUnit runner Nuget package to your xUnit project. I think this is the right package:
https://www.nuget.org/packages/xunit.runner.visualstudio/2.1.0

Related

dotnet test not loading resharper test adapter

We have an nunit3 test project that we're trying to run via command-line in dotnet core that is having problems being identified. In all our debugging we've not found an answer to fixing this.
Background: We build out these tests to test an API site after it's been deployed, alongside standard unit testing. So we package the test up as a DLL to run after we've built out the site, and configure it to run against the site. On our local machines, the tests can't be identified until we install Resharper on our Visual Studio.
After attempting a
dotnet test "path\to\bin\release\Test.dll"
we get the error:
No test is available in path\to\bin\release\Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:.
According to Resharper site, the tools require the run: dotnet tool install -g JetBrains.ReSharper.GlobalTools
doing so I've found the adapters at
C:\Users\USER\.dotnet\tools\.store\jetbrains.resharper.globaltools\2020.3.2\jetbrains.resharper.globaltools\2020.3.2\tools\netcoreapp3.1\any\TestRunner\Adapters
but when trying to load a given adapter dll using /TestAdapterPath, it says it can't find it. any idea how to get this test running?
Ensure your test project has a reference to the test adapter built in:
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
can be pulled from nuget package manager in Visual studio or placed into the section with all other package references.
after this, run dotnet test against your built DLL

Azure Functions v2: Integrate Unit Tests with xUnit in Deployment with Azure DevOps

I created an Azure Function v2 (.NET Core) and added a Core Class library that includes Unit Tests using xUnit. I then created a Build pipeline in Azure DevOps with the tasks Visual Studio build and Visual Studio Test.
But I repeatedly fail to build successfully respectively to have the Unit tests running successfully in the pipeline. Locally everything works fine.
What do I have to do to get the Function App build and unit tested successfully in the Azure DevOps Build pipeline?
Here are the steps that have made it work:
Create the Core Class Library
Reference the Azure Function project via "Add Reference"
Add NuGet packages to the class library -> xunit, xunit.runner.visualstudio and Microsoft.NET.Test.Sdk
Add classes to the class library as described here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-test-a-function#create-test-classes
Go to to the .csproj file of the Azure Functions project as well as the class library for the unit tests and change
<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
to
<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
  <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
  <PlatformTarget>AnyCPU</PlatformTarget>
  <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Set up the Build pipeline and include the following tasks:
........................................................
........................................................
........................................................
Make sure that all files are added before checking in (TFVC) /
pushing (Git)
Check in / Push

What dotnet core cli command(or msbuild commands) does Visual Studio use when Building, Rebuilding and Cleaning the Solution?

I want to know the exact dotnet cli commands that Visual Studio uses when I Build/Rebuild and Clean solution in my dotnet core application?
I know that the dotnet core cli was build on top of msbuild so when you run Build/Rebuild or Clean Solution Visual Studio uses
msbuild commands directly and not the ones from dotnet core cli?
Is that correct?
If this is correct I would like to know which msbuild command or commands it uses with the three actions:
Build Solution
Rebuild Solution
Clean Solution
And which dotnet core cli commands would be equivalent to that?
I know from this post(Relationship between the dotnet cli and the new vs2017 msbuild)
that the following commands do the build, rebuild and clean in dotnet and msbuild.
Dotnet cli:
Build: dotnet build
Rebuild: dotnet build --no-incremental
Clean: dotnet clean
Msbuild:
Build: msbuild /t:build
Rebuild: msbuild /t:rebuild
Clean: msbuild /t:clean
I guess this is not all? This is fine but I would like to see what Visual Studio produces for the actions?
And I am wondering if Visual Studio behavior can be changed so it runs dotnet cli commands instead of msbuid?
Research:
I was building a asp.net core web api project in Visual Studio(Visual Studio 2017 Enterprise Version 15.9.11)
I was looking in Visual Studio Output when I Build/Rebuild and Clean the solution but I could not find anything related to
dotnet core cli or msbuild. Then I went to VisualStudio Tools/Option/"Project and Solution"/"Build and Run" and changed the options:
MSBuild project build output verbosity: tried both "Detailed" and "Diagnostics" options
MSBuild project build log file verbosity: tried both "Detailed" and "Diagnostics" options
The outcome was that the log that was produced in the Output window of Visual Studio was huge and it was difficult to find
the exact command which would be used for the actions. I can see msbuild used in many places in the output but it is a little confusing
to find the exact command.
I also saw this question (Does Visual Studio use MSBuild internally, and what is the exact command?)
This answer says that:
Quote:
"It appears that the MSBuild command line options are not specified,
but rather the MSBuild APIs are called within Visual Studio. Unless
you have the Visual Studio source code to reverse engineer, you cannot
get an equivalent command line."
Is that the same case for dotnet core cli msbuild as well?
Any help or clarification on this is appreciated.
I know that the dotnet core cli was build on top of msbuild so when
you run Build/Rebuild or Clean Solution Visual Studio uses msbuild
commands directly and not the ones from dotnet core cli?
For VS2017, I would think the VS IDE calls msbuild.exe directly when Clean, Build and Rebuild.You can easily check this point by Task Manager or Process Monitor.
As for what you mentioned above:It appears that the MSBuild command line options are not specified, but rather the MSBuild APIs are called within Visual Studio.
I think it's right but only for the eariler vs versions(2010,2013). I've tested with VS2010, when doing building-related actions in VS, it doesn't call MSBuild.exe. So the msbuild in VS2010 is not executed as a separate process.
But for VS2017, when I create projects which target .net core, when doing building-related actions(click the build, clean, rebuild button), it obviously calls the msbuild.exe like below:
About what msbuild commands VS actually executes:
Since now the VS2017 calls msbuild.exe to build .net core or .net fx projects.
In my opinion:
For the solution which only contains a project:
Build the Solution=> msbuild xxx.sln /t:build /p:Configuration=xxx;Platform=xxx
Rebuild the Solution=>msbuild xxx.sln /t:rebuild /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean;build /p:Configuration=xxx;Platform=xxx
Clean the Solution=>msbuild xxx.sln /t:clean /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean
I think every time when we click Build button in VS, it will pick the value of Configuration and Platform from this box, because these two parameters are sure to be passed to MSBuild.exe.
Also, one thing we can discover is that IDE has a check process before start build: It will check if the file is out-of-date and then determine if it need to build or not. But this is not what you ask in your issue and it not affects the command you want, so I skip it.
Also, see this page we can find there are some msbuild-related settings here:
So actually I think the command above should add some parameters like:msbuild ... -m:8 -v:M.
In addition: Though I find building-related action in VS will call msbuild.exe directly. I'm not certainly sure that my command above is 100% correct. I'm afraid no one can ensure that except the guys who develop the menu command in VS IDE. So if i misunderstand anything please feel free to correct me:)
And if you just want to get the exactly same thing like what in VS, you can also have a try devenv.exe. This is the only place in official document which confirms the build switch performs the same function as the Build Solution menu command within the integrated development environment (IDE).

Is there a way to build a VS2017 solution which has .Net Core and .Net Framework projects in Travis CI?

I'm trying to build a solution in Travis CI with two kinds of projects, .Net Core and .Net Framework, but I haven't achieved it, it can build a solution with only .Net Framework or only .Net Core projects, but not for both in the same solution.
I appreciate if someone already has dealt with the same problem and can help me.
Thanks!
I created a standard build for .Net Framework projects and in order to build the .Net Core projects in the same solution, I just created a some post-build commands like this:
dotnet restore EFCore.DbContextFactory.Examples.Data/EFCore.DbContextFactory.Examples.Data.csproj --verbosity m
dotnet restore EFCore.DbContextFactory.Examples.WebApi/EFCore.DbContextFactory.Examples.WebApi.csproj --verbosity m
dotnet restore EFCore.DbContextFactory/EFCore.DbContextFactory.csproj --verbosity m
dotnet publish EFCore.DbContextFactory.Examples.Data/EFCore.DbContextFactory.Examples.Data.csproj
dotnet publish EFCore.DbContextFactory.Examples.WebApi/EFCore.DbContextFactory.Examples.WebApi.csproj
dotnet publish EFCore.DbContextFactory/EFCore.DbContextFactory.csproj
Then for unit test I'm using that command to execute the tests and generate the results file:
dotnet test EF.DbContextFactory.UnitTest.Data\EF.DbContextFactory.UnitTest.Data.csproj --logger "trx;LogFileName=output.trx"
So lastly I publish the tests results on appveyor (Powershell):
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", (Resolve-Path EF.DbContextFactory.UnitTest.Data\\TestResults\output.trx))
And that's it. BTW in order to restore the nuget packages I have this before build script:
nuget restore
Look at appveyor (https://www.appveyor.com/), a CI service for Windows builds

How to run "dotnet xunit PathToLibrary.dll" from command line (in Continous Integration)

I am able to "dotnet xunit" when I am in folder where the project is.
How can I do it from command line where I want to pass already compiled dll as a parameter.
dotnet xunit PathToLibrary.dll
I get an error:
No executable found matching command "dotnet-xunit"
I have copied "xunit.execution.desktop.dll" (get from nuget xunit.core.2.3.0) into current folder, but that does not help.
dotnet-xunit is a per-project CLI tool
Consuming these tools requires you to add a <DotNetCliToolReference> element to your project file for each tool you want to use. Inside the <DotNetCliToolReference> element, you reference the package in which the tool resides and specify the version you need. After running dotnet restore, the tool and its dependencies are restored.
So check that your .csproj contains
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0" />
</ItemGroup>
then do
dotnet restore
This answer isn't a direct answer to OP, but necessary for users of dotnet xunit
dotnet xunit is removed starting from xunit 2.4 Ref: Release Notes 2.4
Excerpt from the Release Notes:
Unfortunately, this release also removes the dotnet xunit runner, as the stability of the runner was never perfect, and it suffered from many assembly-loading related issues. Users from .NET Core can continue to use VSTest (either inside Visual Studio, or via dotnet test).
So, for xunit framework test use the command
dotnet test

Resources