Tag: xunit.net

没有vstest.console.exe发现的xunit测试

我正在整理一组新的unit testing,作为CI工作一起运行。 我使用vstest.console.exe而不是mstest.exe主要是因为它能够从几个框架运行测试,但现在焦点是几个xUnit dll。 这些作业是作为Jenkins管道的一部分运行的。 我已经在几个开发盒上成功测试了所有内容,但到目前为止,烦人的测试发现在任何CI构建盒上都无法正常工作。 这是在添加0.99.8 xUnit测试适配器vsix(也用0.99.7测试)之后。 xUnit dll是使用2.0.0.2378 beta nuget版xUnit构建的。 我用最简单的dll复制了这些症状,使用单一的公共测试方法,在我自己的盒子上正常工作,而不是在任何构建盒上工作。 在Windows 2012上,部署环境非常简单,VS2012安装和xUnit测试适配器。 我通过vstest exe配置文件启用了TpTrace日志记录,一切看起来都很好。 我想我正在寻找一种方法来进一步解决问题(可能是跟踪xUnit发现过程)或解决问题。 为了简化运行几个框架,我宁愿保留使用vstest控制台。 我也通过xUnit codeplex网站写了这个问题。 我已经查看了这篇SOpost,但没有一个建议的解决方案在这里有意义。

在VS2015上使用xUnit测试和UWP应用程序

这是这个问题的后续行动。 我按照这里描述的步骤进行操作,样本测试按预期工作。 这是我第一次使用这个工作样本,但是等待真正的工作设置,这是我遇到麻烦的地方。 作为测试我的应用程序的下一步,我使用“添加引用…”将我的UWP应用程序项目添加到xUnit Test项目中。 现在,在我引用我的项目之后,当我运行测试时(在测试资源管理器窗格VS2015中全部运行),我收到以下错误: Error Payload contains two or more files with the same destination path ‘Assets\SplashScreen.scale-200.png’. Source files: …\Projects\Sample\SampleUnitTest\Assets\SplashScreen.scale-200.png …\Projects\Sample\Sample\Assets\SplashScreen.scale-200.png SampleUnitTest 还有两个错误,正如上面所述,但是指的是Square150x150Logo.scale-200.png和Square44x44Logo.targetsize-24_altform-unplated.png图像文件。 我能理解这些错误意味着什么; 正在测试的应用程序和测试项目都生成目标为相同输出的可视资源(闪屏图像,徽标,任务栏图标等)但这些是注册应用程序并运行(在本地计算机上运行)所必需的我的情况)。 我从来没有遇到过这样一个有争议的问题,即输出相同视觉资源的两个项目,希望有人知道如何解决这个问题。 如果我将项目更改为Class项目,则unit testing不起作用,因此这不是一个选项。 您如何处理xUnit测试项目和正在测试的项目之间的争议情况(可视化资源)?

在VS2015上使用xUnit测试UWP应用程序

我已经设法在VS2015上创建一个xUnit项目来对UWP应用进行unit testing。 这里有一个关于stackoverflow的问题的背景,它给出了这个问题的一些背景。 我可以编译并运行测试,但是当我引用要测试的项目时,会出现以下错误。 —— Run test started —— Updating the layout… Checking whether required frameworks are installed… Registering the application to run from layout… Deployment complete (1857ms). Full package name: “8f4533e5-fec8-415b-94ab-6bce6b37374f_1.0.0.0_x86__5gyrq6psz227t” A user callback threw an exception. Check the exception stack and inner exception to determine the callback that failed. ========== Run test finished: […]

Xunit为每个新测试创建Test类的新实例(使用WebDriver和C#)

有没有办法在使用Xunit的Webdriver(Selenium)在同一浏览器中运行多个测试,目前xunit为每个新测试启动新浏览器,下面是示例代码 public class Class1 { private FirefoxDriver driver; public Class1() { driver = new FirefoxDriver(); } [Fact] public void Test() { driver.Navigate().GoToUrl(“http://google.com”); driver.FindElementById(“gbqfq”).SendKeys(“Testing”); } [Fact] public void Test2() { driver.Navigate().GoToUrl(“http://google.com”); driver.FindElementById(“gbqfq”).SendKeys(“Testing again”); } }

在xunit.net中有一个简单的方法来比较两个集合而不考虑项目的顺序吗?

在我的一个测试中,我想确保集合中有某些项目。 因此,我想将此集合与预期集合的项目进行比较,而不是关于项目的顺序 。 目前,我的测试代码看起来有点像这样: [Fact] public void SomeTest() { // Do something in Arrange and Act phase to obtain a collection List actual = … // Now the important stuff in the Assert phase var expected = new List { 42, 87, 30 }; Assert.Equal(expected.Count, actual.Count); foreach (var item in actual) Assert.True(expected.Contains(item)); } 在xunit.net中有没有更简单的方法来实现这一目标? 我不能使用Assert.Equal因为此方法检查两个集合中项目的顺序是否相同。 […]

如何在xUnit中设置测试用例序列

我在C#中编写了xUnit测试用例。 该测试类包含很多方法。 我需要按顺序运行整个测试用例。 如何在xUnit中设置测试用例序列?

unit testing.NET Standard 1.6库

我无法找到有关如何对.NET Standard 1.6类库(可以从.NET Core项目中引用)进行unit testing的最新文档。 这是我的project.json对我的库来说的样子: { “supports”: {}, “dependencies”: { “Microsoft.NETCore.Portable.Compatibility”: “1.0.1”, “NETStandard.Library”: “1.6.0”, “Portable.BouncyCastle”: “1.8.1.2” }, “frameworks”: { “netstandard1.6”: {} } } 现在剩下的任务是能够创建某种可以进行unit testing的项目。 目标是使用xUnit,因为这似乎是.NET Core团队正在推动的。 我继续创建了另一个.NET Portable库项目,该项目有一个如下所示的project.json: { “supports”: {}, “dependencies”: { “Microsoft.NETCore.Portable.Compatibility”: “1.0.1”, “NETStandard.Library”: “1.6.0”, “xunit”: “2.2.0-beta4-build3444”, “xunit.runner.visualstudio”: “2.1.0” }, “frameworks”: { “netstandard1.6”: { } } } 我在该项目中的测试类如下所示: using USB.EnterpriseAutomation.Security.DotNetCore; using […]

如何处理xUnit .net的Assert.Throws 中的Tasks抛出的exception?

以下异步xUnit.net测试使用标记有async修饰符的lambda失败,因为报告没有抛出exception: [Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup // Exercise system and verify outcome Assert.Throws(async () => await sut.SearchAsync(null, dummyToken)); // Teardown } 为了确保实际抛出ArgumentNullException我明确地使用了try-catch块。 它工作,但结果代码不干净(与第一次测试相比): [Theory, AutoWebData] public async Task SearchWithNullQueryThrows( SearchService sut, CancellationToken dummyToken) { // Fixture setup var expected = typeof(ArgumentNullException); Type actual = null; // […]

validationunit testing中集合/项集的完整映射

我正在使用xUnit.net,AutoFixture和SemanticComparison,并希望validation映射的结果。 在个别项目层面,我很好 。 特定 这些项共享一个识别密钥 我想对两边的值元素进行比较 我不关心订购(并且不希望我的Assertion在重新订购时破坏) 如何使用尽可能多的OOTB组件validation每个输入项是否以DAMP但DRY方式映射到一个且仅一个输出项? 比赛时间: class Input { public string Name, Description; } class Output { public string Name, Description, IgnoreThisField; } 骨架测试: [Theory,AutoData] void MappingWorks( Mapper sut, Input[] inputs) { var outputs = sut.Map( inputs); // TODO assert that every input is mapped // TODO assert that we have have […]

AutoFixture:PropertyData和异构参数

鉴于以下测试: [Theory] [PropertyData(“GetValidInputForDb”)] public void GivenValidInputShouldOutputCorrectResult( string patientId , string patientFirstName ) { var fixture = new Fixture(); var sut = fixture.Create(); sut.DoSomething(); // More code } 我想将夹具创建封装在自己的类中,类似于: [Theory] [CustomPropertyData(“GetValidInputForDb”)] public void GivenValidInputShouldOutputCorrectResult( string patientId , string patientFirstName , HtmlOutputBuilder sut ) { sut.DoSomething(); // More code } 问题是我正在使用PropertyData而后者正在提供两个输入参数。 事实上,我正在尝试自动创建我的夹具作为参数导致exception。 这是CustomPropertyData: public class CustomPropertyDataAttribute : […]