I run tests via nunit3-console (v3.16.2). The value of AppDomain.CurrentDomain.BaseDirectory in the test will be the path to the directory from where the console runner is essentially launched. I can't use TestContext because of the call to AppDomain.CurrentDomain.BaseDirectory is used in a third-party library.
About csproj:
net6.0
nuget Nunit v3.13.3
nuget NUnit3TestAdapter v4.3.1
Command: C:\NUnit.Console-3.16.2\bin\nunit3-console.exe C:\src\solution\Test.Project\bin\Test.Project.dll
Value of AppDomain.CurrentDomain.BaseDirectory: C:\NUnit.Console-3.16.2\bin\agents\net6.0\
Question: Maybe someone knows a workaround
Related
I have this one liner that can publish my project:
& "$($linkToMSBuildEXE)" "$($solutionName)" /t:projectName /p:Configuration="Release"
I need to publish this project and set the assemblyVersion and fileVersion of the output executable. I have tried adding the version:
& "$($linkToMSBuildEXE)" "$($solutionName)" /t:projectName /p:Configuration="Release"/p:Version=1.1.1.1
This doesn't seem to work. Do I need to add an entry to the csproj file? How can I set the versions via the command line.
Install MSBuild.AssemblyVersion package from NuGet.
Use the following or similar command line:
msbuild project.csproj /t:Rebuild /p:AssemblyVersionNumber=1.2.3.4
I have a project where I can not run the tests using dotnet test while my colleague can. The error message I get is
System.IO.FileNotFoundException: No test is available in C:\projects\...\bin\Debug\netcoreapp1.1\Test.AnalyzeFirmwareRollout.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again.
The project does have a reference to Microsoft.NET.Test.Sdk and the target framework is
<TargetFramework>netcoreapp1.1</TargetFramework>
in the csproj file. Any Ideas what could be going wrong here?
For running xUnit tests from command line, you will need the xunit.runner.console package.
We have a .NET C# solution with some first integrationtests, but no unit tests. How do I have to configure the sonar-project.properties to get test execution and code coverage to work?
When using:
sonar.dotnet.visualstudio.testProjectPattern=*.Tests;*.Test
sonar.dotnet.visualstudio.itProjectPattern=*.IntegrationTest
sonar.opencover.installDirectory=C:/Program Files/OpenCover
sonar.gallio.coverage.tool=OpenCover
sonar.gallio.runner=IsolatedProcess
sonar.gallio.it.mode=active
sonar says:
14:42:55.813 INFO p.d.a.m.ModelFactory - The project 'foo.IntegrationTest' has been qualified as a test project.
14:42:55.844 INFO p.d.a.m.ModelFactory - The project 'bar.IntegrationTest' has been qualified as a test project.
...
Gallio won't execute as there are no test projects
When changing the test Patterns:
sonar.dotnet.visualstudio.testProjectPattern=*.IntegrationTest
#sonar.dotnet.visualstudio.itProjectPattern=*.IntegrationTest
gallio executes the integration tests as "unit tests" and code coverage works. Any hints?
I'm using this for code coverage generation.
For example project is Test/Test.csproj
cd ./Test
nuget install Microsoft.CodeCoverage -OutputDirectory ./packages
in ./packages in nested directories will be CodeCoverage.exe
dotnet test --no-build logger trx --collect "CodeCoverage" /p:Debug=full -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CoverageFileName="test.coverage"
In TestResults in nested directories there will be test.coverage file.
Transform it to coveragexml
CodeCoverage.exe analyze /output:test.coveragexml test.coverage
Then use it in sonarscanner
./SonarScannerMsbuild.exe /d:"sonar.cs.vstest.reportsPaths=./**/*.trx" /d:"sonar.cs.vscoveragexml.reportsPaths=./**/*coveragexml"
How can I execute a test case from Command Console using NUnit? I had set of Selenium Tests written in C# based on NUnit framework. I need to execute the test cases simply by running from command console.
In JUnit we can run test case from cmd as
java junit.swingui.TestRunner test.Run
How can we do above in NUnit?
Use nunit-console.exe to run tests from the command line.
For example:
nunit-console.exe /xml:results.xml path/to/test/assembly.dll
This will run the unit tests and save the results in the results.xml file, which you can work with easily.
See the documentation for all of the various command line switches that are available.
I would like to add a few words about the latest version of NUnit. The name of the console application has changed to nunit3-console.exe in NUnit 3. Information about all possible options can be found in the official documentation. For example, run all tests in the assembly (the results are saved into the TestResult.xml file by default).
nunit3-console.exe path/to/test/assembly.dll
I've just find another nice solution:
Adding the following command to the "Build Events" / "Post-Build Events", will run the tests in Nunit-Gui automatically after the project has been built.
I hope this can be useful:
"C:\Program Files (x86)\NUnit 2.6.3\bin\nunit-x86.exe" $(TargetPath) /run
Visual Studio: 2017, 2019(Preview)
On Mac use below command:
nunit-console <path/to/project>/<project-name>/bin/Debug/<project-solution-name>.dll
For example:
nunit-console /Users/pratik/Projects/selenium-mac13/selenium-test/bin/Debug/selenium-test.dll
nunit3-console.exe "path of the testfile (dll)"
Working on a Windows 10 Desktop with Visual Studio
I had a set of tests in C# where I'd set the test method with Category==API.
To run the tests (Nunit3-console) remotely via Bamboo, I added this Bamboo Powershell script:
Invoke-Command -Credential $credentials -ComputerName $Server -ScriptBlock{
$pathToDdrive = "D:"
$pathtoDLL = Join-Path $pathToDdrive -ChildPath "RestOfThePathToDLL"
cd D:\...\NUnit.ConsoleRunner.3.10.0\tools
.\nunit3-console.exe $pathToDLL --where "cat=='API'"
}
I have a .net application built on .net framework 3.5, I am trying to build this application on Jenkins CI server. I've added MSBuild plugin and and have added path to the .exe file of 2.0, 3.5 and 4.0 versions of MSBuild. But my building processes are failing by showing the below error message.
Path To MSBuild.exe: msbuild.exe
Executing command: cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
[Test project] $ cmd.exe /C msbuild.exe Neo.sln && exit %%ERRORLEVEL%%
'msbuild.exe' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Build a Visual Studio project or solution using MSBuild.' marked uild as failure
Finished: FAILURE
Could anyone plz help me out..??
To make the MSBuild plugin work, you need to configure the plugin in the Jenkins management screen.
NOTE: in the newer Jenkins versions you find the MSBuild configuration in the Global Tool Configuration:
Note the "Name" field, where I've called this particular configuration v4.0.30319. You could call it anything you like, but ideally the name will somehow refer to the version.
You'll need to refer to this name later in the Jenkins PROJECT that's failing.
Note: The yellow warning implies that the Path to MSBuild field should be populated with a directory name rather than a file name. In practice you do need to enter the filename here too (ie. msbuild.exe) or the build step will fail.
In the Jenkins project that's failing, go to the MSBuild build step.
The first field in the build step is "MSBuild Version". If you created the build step before configuring any MSBuild versions, the value here will be (default).
After configuring one or more MSBuild versions, the drop down will be populated with the available configurations. Select the one you require.
You can see here that I've now selected the named configuration that matches the installation above.
Jenkins | Manage Jenkins | Configure System
scroll down to the MSBuild section and click MSBuild installations
define the full path to msbuild.exe, on my system I have 3.5 and v4.0.30319
Note - specify the path to 32-bit tools even on a 64-bit system, otherwise you might get an error message:
Building Windows Phone application using MSBuild 64 bit is not supported.
So in Jenkins - it could be for example:
Name: Version 3.5
Path: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
Name: Version 4.0
Path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe
I think you should set an absolute path for "msbuild.exe" in your Jenkins configuration,
for example:
C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe
You can also add the path where the msbuild.exe is, to the PATH system environment variable of the node (or nodes) that is running that specific job.
You could try executing the
%comspec% /k ""c:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
command, which will temporarily update your environment path variables to reflect the VS2010 build environment. Execute this before you call MSBUILD and see what happens. I use this in my own build scripts with no issues.
Side note; it's very likely counterproductive to have multiple versions of MSBUILD on your PATH. Concentrate on getting one version working and go from there.