Tag: xunit.net

使用FakeItEasy,是否可以创建一个采用generics类型参数的虚拟对象

我有以下测试: [Fact] public void StartProgram_CallsZoneProgramStart() { var zone = A.Fake(); zone.StartProgram(); A.CallTo(() => zone.ZoneProgram.Start(null, A.Dummy<ActionBlock>())).MustHaveHappened(Repeated.Exactly.Once); } 它正在创建一个ActionBlock类型的虚拟对象,它被传递给MustHaveHappened调用。 zone.StartProgram肯定会调用zone.ZoneProgram.Start方法,但FakeItEasy看不到此调用。 它返回以下错误消息: Assertion failed for the following call: ZoneLighting.ZoneProgramNS.ZoneProgram.Start(, ActionBlock\`1 Id=1) Expected to find it exactly once but found it #0 times among the calls: 1: ZoneLighting.ZoneProgramNS.ZoneProgram.Start(inputStartingValues: Faked ZoneLighting.ZoneProgramNS.InputStartingValues, interruptQueue: ActionBlock`1 Id=2) 2: ZoneLighting.ZoneProgramNS.ZoneProgram.Start(inputStartingValues: , interruptQueue: ActionBlock`1 Id=2) […]

带有参数化unit testing的.NET测试框架,每个组合显示红色/绿色?

当您具有Xunit testing* Y配置时, 参数化unit testing非常有用。 我有3个unit testing,每个必须在5种特定情况下运行。 我使用xUnit.net的Theory / PropertyData function ,效果很好。 问题:在Test Runner UI中,每个unit testing有一个绿色/红色符号,表示3 。 这使得评估进度变得困难:符号为红色,直到所有配置完美运行。 我想要15个符号,每个unit testing*配置一个,以了解哪个特定组合出错了。 xunit.net 尚未实现该function以显示15个符号。 我愿意切换到另一个测试框架只是为了获得这个function。 问题:任何.NET测试框架都有此function吗? 任何类型的报告都很好(GUI,HTML等)

伪造/模拟接口给出“没有默认构造函数”错误,怎么会这样?

我正在尝试编写存储库实现的unit testing。 存储库使用RavenDB作为数据库。 对于unit testing,我想模拟RavenDB部分。 为了创造嘲笑(假货)我正在使用FakeItEasy。 我认为由于RavenDB API是通过接口访问的,因此模拟/伪装不会有任何问题。 但是,在尝试实例化特定模拟时,我确实遇到了问题。 我的unit testing代码的相关部分如下所示: [Fact] public void Test() { UserDocument doc = …; IQueryable where = A.Fake<IQueryable>(); A.CallTo(() => where.First()).Returns(doc); IRavenQueryable query = A.Fake<IRavenQueryable>(); IDocumentSession session = A.Fake(); A.CallTo(() => session.Query()).Returns(query); IDocumentStore store = A.Fake(); A.CallTo(() => store.OpenSession()).Returns(session); . . . } 在实例化IRavenQueryable假的时候,我得到了一个exception。 这是来自Xunit.net跑步者的日志: UnitTest.Test : FakeItEasy.Core.FakeCreationException : […]

xUnit.net Test Stripper

是否有可用的测试剥离器(在xUnit测试模式中定义),它支持删除包含标记为[Fact]等的方法的类以及从二进制文件[作为构建过程的一部分]对xunit.dll的依赖性? 有关完整要求和上下文的更多详细信息, 请参见此xUnit CodePlexpost 。 如果失败了(删除了测试和对DLL的引用),任何人都有一个实用程序/经过validation的干净方法来删除xunit.dll依赖,而不会在.vcproj文件中进行太多的修改等。 开源首选。 NUnit的一个干净的书面文件可能会作为基础。 注意:我知道将代码嵌入到程序集中的负面影响 – 这个问题不是关于这个问题(除非你在阅读了codeplex线程后感到遗漏了一些关键点)。

如何将服务配置传递给Xunit项目测试控制器?

我目前有以下设置。 启动类: Startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.Configure(Configuration.GetSection(“AzureStorageConfig”)); services.AddTransient(); } //other config settings … } 类: AzureStorageConfig //store the azure account details etc… public class AzureStorageConfig { public string AzureURL { get; set; } public string […]

“unit testing1”,但在其下方,列表为空

我克隆了https://github.com/SonarSource/sonar-examples.git然后在SonarSource / sonar-examples / tree / master / projects / languages / csharp下打开命令提示符并运行以下命令(基于“unit testing执行”)结果导入(C#,VB.NET)“@ docs.sonarqube.org/pages/viewpage.action?pageId=6389772): MSBuild.SonarQube.Runner.exe begin /k:”org.sonarqube:csharp-simple-sq-scanner-msbuild” /n:”C# :: Simple Project :: SonarQube Scanner for MSBuild” /v:”1.0″ /d:sonar.cs.xunit.reportsPaths=”%CD%\XUnitResults.xml” MSBuild.exe /t:Rebuild packages\xunit.runner.console.2.1.0\tools\xunit.console.exe XUnitProject1\bin\Debug\XUnitProject1.dll -xml %CD%\XUnitResults.xml MSBuild.SonarQube.Runner.exe end 在公制/测试/列表下,我得到“unit testing1”,这是可以的,但在它下面列表是空的: 为什么? 控制台的相关部分: INFO: Sensor org.sonar.plugins.csharp.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor INFO: Parsing the XUnit Test Results file C:\workspace\SonarSource-sonar-examples-92828b2\projects\languages\csharp\XUnitResults.xml INFO: Sensor org.sonar.plugins.csharp.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor […]

为什么Image.Clear(x)之后的颜色不完全等于颜色x?

此问题的示例代码在很大程度上是不言自明的,因此: [Fact] private void Color_in_should_equal_color_out() { var bitmap = new Bitmap(128,128,PixelFormat.Format32bppArgb); var color = Color.FromArgb(30,60,90,120); using (var g = Graphics.FromImage(bitmap)) { g.Clear(color); } var result = bitmap.GetPixel(0,0); Assert.Equal(color, result); } 在这种情况下,我希望背景的颜色与我清除它的颜色相同。 相反,我得到这个: Assert.Equal() Failure Expected: Color [A=30, R=60, G=90, B=120] Actual: Color [A=30, R=59, G=93, B=119] 这怎么可能呢? 一些通过: Color.FromArgb(0, 0, 0, 0); Color.FromArgb(255, 255, 255, […]

如何在Approvaltests中添加对xunit的Theory属性的支持

当我尝试使用[Theory]属性修饰的unit testing时使用批准时,它说: System.Exception: System.Exception : Approvals is not set up to use your test framework. It currently supports [NUnit, MsTest, MbUnit, xUnit.net] To add one use ApprovalTests.StackTraceParsers.StackTraceParser.AddParser() method to add implementation of ApprovalTests.StackTraceParsers.IStackTraceParser with support for your testing framework. To learn how to implement one see http://blog.approvaltests.com/2012/01/creating-namers.html at ApprovalTests.StackTraceParsers.StackTraceParser.Parse(StackTrace stackTrace) at ApprovalTests.Namers.UnitTestFrameworkNamer..ctor() at ApprovalTests.Approvals.GetDefaultNamer() at […]

Xunit的App.config

我正在为一些依赖于某些配置设置的辅助类编写一些xUnit测试,这些配置设置通常存储在执行项目的App.config或Web.config中。 配置如下所示: 我正在使用GUI运行程序(xunit.gui.clr4.exe)和xUnit控制台运行程序(在Jenkins CI服务器上)运行xUnit 1.9。 目前,我可以通过手动设置xunit.gui.clr4.exe.config和xunit.console.exe.config文件,将这些配置值“注入”到测试环境中; 然而,这很乏味且容易出错。 我也可以在灯具中模拟这些配置设置。 但是在10个不同的文件中使用相同的夹具是相当重复的。 有没有更好的方法来使用xUnit模拟这些配置设置,例如为测试项目提供App.config文件?

xUnit和Moq不支持async – 等待关键字

我试图发现如何将async和await关键字应用于我的xUnit测试。 我使用的是xUnit 1.9和Async CTP 1.3。 这是我的测试用例 我有一个接口,它指定一个异步方法调用 public interface IDoStuffAsync { Task AnAsyncMethod(string value); } 我有一个消耗接口并调用异步方法的类 public class UseAnAsyncThing { private readonly IDoStuffAsync _doStuffAsync; public UseAnAsyncThing(IDoStuffAsync doStuffAsync) { _doStuffAsync = doStuffAsync; } public async Task DoThatAsyncOperation(string theValue) { await _doStuffAsync.AnAsyncMethod(theValue); } } 在我的测试中,我希望检查方法DoThatAsyncOperation是否使用正确的值调用方法,因此我模拟了接口并使用Moq来validation调用 [Fact] public async void The_test_will_pass_even_though_it_should_fail() { var mock = new Mock(); var […]