开发者

MSBuild - trying to run xUnit (.net) tests

I'm trying to set up a C# project that'll run xUnit tests when I build, so I can use them in continuous integration. I have a regular project, a class library test project using xUnit, and my test runner project. From everything I've read, it appears that I should be able to get this working by doing this in the test runner project:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Test"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  [auto-created project stuff]
  <UsingTask AssemblyFile="xunit.runner.msbuild.dll"
      TaskName="Xunit.Runner.MSBuild.xunit" />
  <Target Name="Test">
    <xunit Assembly="$(MSBuildProjectDirectory)\..\OnePageOneDb.Tests\bin\Debug\OnePageOneDb.Tests.dll" />
  </Target>
</Project>

When I build my solution after a change (usually editing the .csproj file), I get this:

The "Xunit.Runner.MSBuild.xunit" task could not be loaded from the assembly C:\Users[myusername]\Code\OnePageOneDb\OnePageOneDb.TestRunner\xunit.runner.msbuild.dll. Could not load file or assembly 'file:///C:\Users[myusername]\Code\OnePageOneDb\OnePageOneDb.TestRunner\xunit.runner.msbuild.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

Even if I add xunit.runner.msbuild.dll and xunit.runner.utility.dll to the project in the location it refers to, I get this message. But if I build again with no changes, I consistently get this:

The "xunit" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

But I've checked all these things:

  1. The task class in xunit.runner.msbuild.dll is Xunit.Runner.MSBuild.xunit (and xunit is lowercase in the class name).
  2. The task class inherits from Task, which implements ITask.
  3. So maybe there's a problem in UsingTask, but I don't know what it is.

(I also thought the problem might be that xunit.runner.msbuild.dll is targeted at .NET 2.0, and I'm using VS 开发者_开发问答2010, but I recreated the test runner project in .NET 2.0 and the problem persisted.)

Can anyone help?


You need to specify correct path to xunit.runner.msbuild.dll. First of all, you can just set the full path and test that xunit just works as you want. But for real environment you should specify relative path to the dll.

<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\..\lib\xunit\xunit.runner.msbuild.dll"
           TaskName="Xunit.Runner.MSBuild.xunit" />

MSBuildProjectDirectory is a reserved property and contains "the absolute path of the directory where the project file is located".

EDIT:

Try to use target by full name Xunit.Runner.MSBuild.xunit

<Target Name="Test">
    <Xunit.Runner.MSBuild.xunit Assembly="$(MSBuildProjectDirectory)\..\OnePageOneDb.Tests\bin\Debug\OnePageOneDb.Tests.dll" />
</Target>


I get exactly the same error message if I have Pex and Moles installed. Everything works fine after uninstalling them.


By default building in "release" configuration triggers running xunit tests. If you are trying to disable running xunit tests in tfsbuild pass the following build parameter. This can be useful in the new cross platform builds where running unit tests is a separate step.

/p:RunXunitTests=false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜