简体   繁体   中英

Running Nunit on console through restoring NuGet Package

I am currently working on a project in C#, and trying to get NUnit to run on my project in a Jenkins Build through restoring the package in NuGet. We do not want to install NUnit on all of our Jenkins machines so installing it directly on the box is not an option.

We've investigated the use of NUniter Runners as suggested in this link: https://peteris.rocks/blog/running-nunit-with-msbuild-on-windows-and-mono/

But, we receive an error that the tools do not exist "C:\\Users\\Name\\NewBranch\\project\\project.Tests\\project.Tests.csproj(121,3): error MSB6003 : The specified task executable "cmd.exe" could not be run. The working directory "C:\\Users\\Name\\NewBranch\\project\\ packages\\NUnit.Runners.3.4.1\\tools" does not exist."

How do I execute NUnit tests from the command line without having NUnit installed directly on the machine?

the easiest way is to dump there 2 lines in the packages.config which should be in the same folder as your project.Tests.csproj

<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit.Runners" version="2.6.4" />

Assuming you have a target in your .csproj which is like this:

<Target Name="NugetRestore">    
    <Exec Command="nuget.exe restore" />
</Target>

if you use a solution level build.config, then add this instead

<Target Name="NugetRestore">    
    <Exec Command="nuget.exe restore $(YourSolution).sln" />
</Target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM