MSBuild-尝试运行xUnit(.net)测试 [英] MSBuild - trying to run xUnit (.net) tests

查看:83
本文介绍了MSBuild-尝试运行xUnit(.net)测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个C#项目,该项目在构建时将运行xUnit测试,因此可以在持续集成中使用它们.我有一个常规项目,一个使用xUnit的类库测试项目以及我的测试运行器项目.从我读过的所有内容来看,似乎应该可以通过在测试运行器项目中执行以下操作来使它正常工作:

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>

更改后(通常是编辑.csproj文件)构建解决方案时,会得到以下提示:

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

"Xunit.Runner.MSBuild.xunit"任务 无法从程序集中加载 C:\ Users [myusername] \ Code \ OnePageOneDb \ OnePageOneDb.TestRunner \ xunit.runner.msbuild.dll. 无法加载文件或程序集 'file:///C:\ Users [myusername] \ Code \ OnePageOneDb \ OnePageOneDb.TestRunner \ xunit.runner.msbuild.dll' 或其依赖项之一.系统 找不到指定的文件. 确认 声明是正确的,即 程序集及其所有依赖项 可用,并且该任务包含 一个实现的公共类 Microsoft.Build.Framework.ITask.

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.

即使我将xunit.runner.msbuild.dll和xunit.runner.utility.dll添加到项目所指位置中,我也会收到此消息.但是,如果我再次构建而没有任何更改,我将始终得到以下信息:

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:

找不到"xunit"任务.查看 以下内容:1.)的名称 项目文件中的任务是相同的 作为任务类的名称. 2.) 任务类是公共"并实现 Microsoft.Build.Framework.ITask 界面. 3.)任务正确 在中用声明 项目文件或* .tasks文件中 位于 "C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319" 目录.

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. xunit.runner.msbuild.dll中的任务类为Xunit.Runner.MSBuild.xunit(并且xunit在类名中为小写字母).
  2. 任务类继承自Task,该任务实现了ITask.
  3. 因此UsingTask可能存在问题,但我不知道它是什么.
  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.

(我还认为问题可能是xunit.runner.msbuild.dll面向.NET 2.0,并且我使用的是VS 2010,但我在.NET 2.0中重新创建了测试运行器项目,问题仍然存在. )

(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.)

任何人都可以帮忙吗?

推荐答案

您需要指定 xunit.runner.msbuild.dll 的正确路径. 首先,您可以设置完整路径并测试xunit是否可以按需要工作. 但是对于真实环境,您应该指定dll的相对路径.

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 保留的属性并包含"项目文件所在目录的绝对路径".

尝试全名使用目标 Xunit.Runner.MSBuild.xunit

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

这篇关于MSBuild-尝试运行xUnit(.net)测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆