问题标签 [xunit.net]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
xunit.net - 如何使用 PropertyData 将字符串数组传递给理论测试
我有一个带有以下签名的测试方法:
我的财产看起来像这样:
Xunit 抛出 System.InvalidOperation: Expected 1 parameter, got 2 parameters
有任何想法吗?
silverlight - How to run F# Silverlight Library project holding xUnit.net Contrib based unit tests?
I am unaware of any project templates for F# Silverlight 4 unit tests (I searched Online for templates through Add Project), so I am using the standard F# Silverlight Library project to hold my unit tests (which are just file links to the main unit test project files). I am using xUnit.net Contrib for Silverlight. So everything compiles but I don't know how to run the tests! TestDriven.NET works for my normal unit test project but not this Silverlight unit test project. I tried to use the normal xUnit GUI runner but that doesn't work either. Any ideas?
Update
The xUnit.net Contrib folks recommended using Statlight as a standalone console runner. After adding System.Xml.Linq to my test project with Copy Local=true (my project doesn't need it but Statlight does) I was able to run the executable pointing at my test assembly without any errors except it was unable to find any tests.
I tried lots of things to try and allow the tests to be found. I gave explicit namespaces to my test modules. I tried test method names without spaces. I tried types with instance members instead of functions in modules. I even tried the explicit --MethodsToTest
flag. Nothing works.
I'm not sure if this would be a problem with Statlight or xUnit.net Contrib.
Please note that I am merely trying to test a plain library which can be consumed by Silverlight projects and doesn't actually use any Silverlight features (indeed, I don't have any prior Silverlight experience!).
Update 2
I was able to add the normal xunit assembly to my project through NuGet (which "forces" it in despite not being built for Silverlight) and then run the tests successfully using Testdriven.NET. But I'm not sure if this is "cheating". Perhaps not because my tests are still compiled against the Silverlight version of my library...?
Update 3
While I still haven't had any luck with a "legit" xunit solution, I was able to get Statlight to run some NUnit tests. Except, it only recognizes tests on instance methods of a class, it doesn't recognize tests on functions of a module (while it can handle these just fine in a normal project). Bummer. (I filed an issue with Statlight)
Update 4
I've figured out a super hacky but workable solution to my problem, still looking for something better though. All of my tests are Xunit tests (file links to the non-Silverlight test project) written as functions in modules but I can't get Statlight to find any of the tests. However, I was able to get Statlight to run NUnit tests which are written in the traditional fashion as instance members of a type. Thus I was able to whip up the following single NUnit test which finds all the Xunit tests in the assembly and invokes them (so I can only see one failing test as a time, but other than that it does work well):
xunit.net - xUnit.net 不捕获控制台输出
我刚开始测试 xUnit.net,但它似乎没有像我预期的那样捕获任何输出(控制台、调试、跟踪)。
那可能吗?我正在使用带有 xUnit.net 1.8 的示例 .NET 4.0 类库。
c# - 伪造/模拟接口会给出“没有默认构造函数”错误,这怎么可能?
我正在尝试编写存储库实现的单元测试。该存储库使用 RavenDB 作为数据库。对于单元测试,我想模拟 RavenDB 部分。为了创建模拟(假货),我正在使用 FakeItEasy。我认为模拟/伪造不会有任何问题,因为 RavenDB API 是通过接口访问的。
但是,在尝试实例化特定模拟时,我确实遇到了问题。我的单元测试代码的相关部分如下所示:
当实例化 IRavenQueryable 假我得到一个异常。这是来自 Xunit.net 运行器的日志:
“没有找到默认构造函数”没有任何意义,因为我试图伪造的是一个接口。有没有人建议问题可能是什么?
visual-studio-2010 - xUnit + Gallio + Visual Studio 2010 中的代码覆盖率
我正在尝试找到一种从 mstest 迁移到 xunit 的方法,并且仍然受益于 IDE 集成,这使我首先选择了 mstest。Gallio 似乎实现了这个崇高的目标,而且它是免费的(不需要 Reshaper 或 TestDriven.net)。但我无法让代码覆盖工作。
我的解决方案包含两个项目:项目 SUT(我需要测试的程序集)和项目 SUT.Tests,它是一个 VS 测试项目(这允许 Gallio 在 VS 的测试视图中显示 xunit 测试)。我在 Local.testSettings 中为 SUT.dll 启用了代码覆盖率,并且检测到位。测试运行完成后没有代码覆盖。代码覆盖结果窗口报告:生成空结果:未使用任何检测的二进制文件。查看任何仪器问题的测试运行详细信息。不幸的是,测试运行细节不包含任何“仪器问题”。我尝试取消选中仪器组件复选框并重新运行单元测试;同样的结果。
知道有什么问题吗?
我的设置:
- Windows 7 x64
- VS 2010 Premium (SP1)
- xUnit 1.8
- Gallio 3.3.1 x64(安装程序,不是 zip)
msbuild - 使用 MSBuild 使用 TeamCity 运行 XUnit 测试
我试图让 TeamCity 在构建过程中运行 XUnit 测试。所以我创建了一个单独的文件 - MyProject.msbuild - 与 .sln 文件位于同一文件夹中,如下所示:
但是,无论我做什么,VS2010 都讨厌我在元素中包含元素。如果我在文件上运行 MSBuild,它会告诉我更多信息:
所以我目前的猜测是它没有以某种方式成功加载 xunit.runner.msbuild.dll - 或者我做了其他奇怪的事情。
但是,我认为如果它无法加载 xunit.runner.msbuild.dll,它会告诉我这件事。我确保该文件未被阻止(通过使用 7zip 解压缩 xunit 发行版)。
有什么想法可以让 MSBuild 吞下我的构建文件并运行测试吗?
c# - 监控在 CI 中运行的单元测试
我想监视在 CI 中运行的 xunit.net 测试(如果您知道 nunit 的类似方法,它也可能会有所帮助)。
运行时间加倍的集成测试,我想获得方法调用时间和资源使用情况等信息。
我启动了 Windows 性能监视器,但我不清楚在测试中花费的时间以及为什么它在执行中加倍。
有什么建议吗?谢谢!
visual-studio-2010 - 带有 xUnit、Assert.Throws 和“用户代码未处理异常”的 Visual Studio
我正在尝试使用 xUnit 1.8.0.1549 在 dll 应用程序(VS2010/C#)中运行测试。为此,我使用项目属性中“启动操作”下的“启动外部程序”通过 Visual Studio 运行 xUnit,通过 GUI 运行程序 (C:\mypath\xunit.gui.clr4.x86.exe) 运行 dll。
我想测试某些方法是否引发异常,为此,我使用如下内容:
问题是调试器在我的方法内停止,当引发异常时说“用户代码未处理异常”。这很糟糕,因为它一直停止 gui 运行器,迫使我按 F5。我想顺利运行测试,我该怎么做?谢谢
c# - VSUTF、NUnit、xUnit.NET、MbUnit 与 SUTF 中的异步测试?
Silverlight 单元测试框架有一个 [Asynchronous] 属性 (AsynchronousAttribute),它会导致测试仅在 EnqueueTestComplete() 被调用时结束。这允许一种简单的方法来编写需要在事件结束之前等待事件发生的测试。现在我试图从似乎是最流行的选择中挑选一个最喜欢的通用单元测试框架——VSUTF、NUnit、xUnit.NET、MbUnit,我想知道——你将如何使用这些框架进行异步测试?
我想我可以推出一些自定义代码来执行 Monitor.Wait 或 ResetEventWaitOne 并在测试方法结束时调用它,然后在测试结束时执行 Pulse/Set,但我正在查看是否存在通用/内置解决方案。
这是如何在 SUT 中完成的示例(来自http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7)。
rake - 如何在 Albacore 中使用 nunit 任务的 skip_test_fail 参数?
Albacore 发行说明说xunit 任务支持一个skip_test_fail
参数
“防止 rake 在 xunit 测试失败时中止构建。这在持续集成场景中很有用,例如与 TeamCity 一起运行。”
没有显示示例,我尝试使用它(如下)没有成功。它应该如何工作?