I have developed some End to End tests using Selenium, and Nunit.
I need to run the test cases cross-platform so I created a .net core class library project and developed the tests.
Now I am struggling with figuring how to run the tests outside visual studio.
The first step I did is publishing the project using:
dotnet publish project
Then I found out that I can run Nunit tests using nunit-console.exe, but I'm not sure that it supports cross-platform.
Is what I am trying to accomplish doable? or shall I replace Nunit with other option?
To run .Net Core tests, including NUnit tests, use the dotnet test command. It is cross-platform.
What I did to achieve running Nunit Test Cases cross platform:
1- Running dotnet publish project with specifying target runtime.
3- Running dotnet vstest with specifying file containing tests.
Related
I saw a couple of similar questions but so far I found no single answer to the problem of integrating the publishing step with my build process. Unfortunately the dotnet publish command rebuilds the project again meaning that if I put the "dotnet publish" command in the project's Post-Build steps I get an infinite loop of building retries.
What I want to achieve is to get an exe built for my .NET Core 2.2 Console App for a few selected environments eg. osx and windows-10, possibly linux too, each in its own folder. Obvious condition is that it has to be integrated with the build, so no extra manuals steps (commands) are required. This has to work from within VS2019 Pro as well in CI (like AzureDevOps).
Is this basic step achievable or .Net core was a major step-back in the progress of software development?
I hope I just miss something and I am just grossly exaggerating. :)
Thanks, Radek
How do I integrate exe publishing with the VS2019 build of the console
.net core 2.2 application?
Actually, I think you do not need to worry about this.
dotnet publish already contains the build process. Publish process will first execute Build and then run publish. In a word, Build is a part of Publish process.
So when you input dotnet publish under Build, you will get an infinite loop of building retries.
Solution
----- Just delete post-build event in xxx.csproj file and just dotnet publish directly and it will run the build process first.
You can test in the local VS and when you right-click on your project-->Publish, it will show the step in the output windwow.
In addition, as far as I know, Azure DevOps has a task called dotnet publish which contains Build.
And if you want to do some msbuild custom target only for publish step, you can add a condition like Condition="'$(DeployOnBuild)'=='true'", it will execute for Publish process rather than the normal build step(right-click on your project-->Build).
<Target Name="testone" Condition="'$(DeployOnBuild)'=='true'" AfterTargets="Build">
xxxxxxxxxxxxxx
</Target>
---------------Update 1----------------
First question
Actually, the build of the publish is the pure process and then publish will copy the content of the build output into publish folder. So the execute program is just from the build output folder.
See the publish log:
So you should not specify a publish target under the build process. This is superfluous.
Second question
To generate this program for Window-10, linux or osx, you can try these command line to publish your project:(Release is the standard release build configuration)
For Win-10:
dotnet publish -r win10-x64 -c Release --self-contained
Linux:
dotnet publish -r linux-x64 -c Release --self-contained
For osx:
dotnet publish -r osx.10.12-x64 -c Release --self-contained
In this way, the project is first built according to the specified runtime and then published.
More info about .NET Core RID Catalog, you can refer to this document.
Update 2
I think you should change the configuration in this package UI:
Then click Save.
Also, when you publish this web project, please try to delete bin and obj folder and then publish it.
Debug: bin\Debug\netcoreapp2.1\publish
Release: bin\Release\netcoreapp2.1\publish
Or you should use dotnet command as I described to publish the project. The path is under Debug or Release folder.
What I want to achieve is to get an exe built for my .NET Core 2.2
Console App for a few selected environments eg. osx and windows-10,
possibly linux too, each in its own folder. Obvious condition is that
it has to be integrated with the build, so no extra manuals steps
(commands) are required. This has to work from within VS2019 Pro as
well in CI (like AzureDevOps).
Is this basic step achievable or .Net core was a major step-back in
the progress of software development?
It's a good idea but as I know what you want is not 100% supported for now.
It seems that your expected scenario is:
Click the Build(F5) button=>Project will be built in different platforms win-x64,win-x86,linux-x64...,also will be published in different platforms automatically with self-contained mode.
But the fact is:
1.Click the Build button(Build(F5) equals to the Build button in project context) will run the Build Target (A default built-in target for each project for build). => dotnet build in command-line.
2.Click the Publish button will run the Publish Target (A default built-in target for each project for publish). => dotnet publish in command-line.
3.If you have any build/publish command in post-build event, it will result in an expected loop. So it's hard to combine publish with build perfectly since they're two actions in VS with different button/behavior/corresponding command. (Only dotnet publish command can recognize --self-contained)
4.To build/publish the projects in parallel, the batch file or msbuild targets file is a good choice.
#1.Build different platforms using one build command see this. #2.Publish different platforms using one command see this. (They both use custom .targets to do the job)
Suggestions:
According to your scenario, I think you can consider using #2. It's not necessary for you to build with different platforms during your normal development.
1.In local VS when you're developing and debugging:
The default build button/option is enough for you to debug.
2.In local VS when you want to publish the project in different platforms:
Use #2 above so that you can publish them using cmd.exe or PS.exe. (Via command dotnet msbuild -restore -t:PublishAllRids)
3.When you're automating the CI pipeline in AzDeops(Also use #2):
A CMD/PS task with dotnet msbuild -restore -t:PublishAllRids command is enough. Dotnet publish will build automatically if we don't pass --no-build argument.
4.Azure Devops Service suggests separate the jobs in different tasks, it's not recommend to Integrate Publish with Build heavily, especially for .net core projects. (Here's official sample about CI for .net core projects.)
I want to try .netcore and utilize my Linux machines for test execution purposes. Can I run specflow mstest in Linux machines from Azure DevOps pipeline using .netcore?
What steps I should follow?
There's a video guide introduced that Integrating SpecFlow with Azure DevOps using .NetCore.
It has the step by step guide on integrating a Visual Studio SpecFlow/Selenium WebDriver project with Azure DevOps. And utilizing Azure DevOps Repositories and Pipelines to execute the SpecFlow Tests.
In your scenario, you need to setup a private agent on your Linux machines and install the required components/SDKs etc to run the test. In the guide it using the VSTest, you can also try MStest.
If you cannot run it directly on the Linux machine, then you can try running in Linux container. Reference : https://github.com/techtalk/SpecFlow/issues/1662
In addition to specflow tests on a linux machine you need Mono installed in order to generate reports with SpecFlow+. Make sure you have installed Mono on the machine you are using to execute your tests (i.e. on your development machine or build server). Refer to Additional Requirements for Non-Windows Users for details.
you should try this
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/yourtest.csproj'
I have codedUI and unit tests in my solution. Solution and the unit tests are successfully building in TFS 2017. CodedUI tests fail. I get an error.
Failed to initialize the unit test extension 'urn:CodedUITest': A unit test extension is not registered for the following attribute: Microsoft.VisualStudio.TestTools.UITesting.CodedUITestAttribute.
All the tests successfully pass in my local machine. What configuration am I missing in my build process?
kindly, help!.
According to the error info, seems the issue should more related to build agent Environment setting. Make sure you have Visual Studio and Coded UI features installed on the build agent. You could double check this by remote to the build agent and manually run Code UI in the agent machine instead of through TFS build.
If you are using Nuget Visual Studio Test Platform Installer , this is not support for now, take a look at the similar issue: VSTS build release agent unable to run Coded UI tests when using the Nuget VsTest platform
Currently Coded UI and UWP tests not support with VSTest platform
nuget package. /cc #PBoraMSFT for blog/doc and timeline for support.
I am attempting to use FAKE to build and test a solution that includes an ASP.NET 5 / MVC 6 site (beta 8) and a unit test project for the site. I'm using the latest xUnit and have set up the xunit.runner.dnx command in my unit test project. Visual Studio can see the tests and run them without issue.
Using FAKE I've been able to get standard xUnit tests to run, but I'm unsure how to properly compile the site and run the DNX tests. If it matters, I'm targeting the full CLR, not just CORECLR.
What they basically do is create a DNX command that will run the unit tests in the context of a command line. You can see how they did it there.
Now... if you want to run this in the context of Visual Studio, it's already built-in with MSTest Runner (haven't managed to make it work with ReSharper).
If you want to run the tests in command line mode, go to your test project folder (with project.json in there) and run dnx test.
As far as compilation goes, Roslyn will take care of it and you do not need to emit DLLs.
Take a look at https://github.com/djanosik/FAKEX. It was designed to do FAKE builds on DNX.
I am using Visual Studio 2015 for a MVC-/angularJS -project.
I have written a couple of Integrationtests using the Protractor nuget package.
The problem is, I can only run these tests on deployed versions of the project.
Is there a way to run the Integrationtests against a freshly compiled version in running in debug-Mode on the same machine?
Maybe this blogpost will help you: NUnit Unit Testing of ASP.NET Pages.
AngularJS or not shouldn't make a difference with this guide.