草庐IT

stubbing

全部标签

c# - 如何改变 stub 的行为?

我可以在运行时更改stub的行为吗?像这样的东西:publicinterfaceIFoo{stringGetBar();}[TestMethod]publicvoidTestRhino(){varfi=MockRepository.GenerateStub();fi.Stub(x=>x.GetBar()).Return("A");Assert.AreEqual("A",fi.GetBar());fi.Stub(x=>x.GetBar()).Return("B");Assert.AreEqual("B",fi.GetBar());//Currentlyfailshere}我的代码示例在给

c# - 无法生成方法 stub Visual Studio 2015 + Resharper 9

我刚刚将VisualStudio升级到2015Pro版本并安装了resharper9.0。现在,当我创建一些方法时,我无法生成如图所示的方法stubhereVisualStudio2015不显示生成方法stub的解决方案。甚至resharper也不会在左侧显示灯泡。另一件事:当我尝试向方法添加新变量时,同样的事情-resharper没有任何建议-左侧没有灯泡。是否缺少某些配置或关闭了某些功能?更新:好吧,我找到了一张小支票,这有助于解决第一个问题。Resharper选项->代码检查->设置->取消选中“不显示VisualStudio灯泡” 最佳答案

c# - 使用 Rhino Mocks 从模拟/ stub 中引发事件

如何使用RhinoMocks从模拟/stub引发事件?我在网上找到了这个问题的一些答案,但他们似乎都使用Record/Replay-syntax,但我使用的是Arrange/Act/Assert语法。有什么建议吗?一个小例子...假设我正在使用MVVM模式并拥有这个模型类:publicclassMyModel{privateint_myValue;publiceventEventHandlerValueChanged;publicvoidSetValue(intnewValue){_myValue=newValue;if(ValueChanged!=null){ValueChanged

c# - 异步单元测试中的 stub 任务返回方法

假设我有以下类和它所依赖的接口(interface):publicclassMyController{privateIRepository_repository;publicMyController(IRepositoryrepository){_repository=repository;}publicasyncTaskMethodUnderTest(intsomeId){varo=await_repository.FindById(someId);//updateoawait_repository.Commit();}}publicinterfaceIRepository{Task

javascript - Jasmine Spies.and.stub 方法

我一直在通读Jasmine文档,并且一直在努力理解Spies.and.stub方法的实际作用。英语不是我的母语,所以我什至不知道“stub”这个词的实际含义,也没有我的语言的翻译。在文档中它说:Whenacallingstrategyisusedforaspy,theoriginalstubbingbehaviorcanbereturnedatanytimewithand.stub.describe("Aspy",function(){varfoo,bar=null;beforeEach(function(){foo={setBar:function(value){bar=value;

javascript - 如何使用 sinon stub new Date()?

我想验证各种日期字段是否已正确更新,但我不想在预测newDate()何时被调用时乱七八糟。如何stubDate构造函数?importsinon=require('sinon');importshould=require('should');describe('tests',()=>{varsandbox;varnow=newDate();beforeEach(()=>{sandbox=sinon.sandbox.create();});afterEach(()=>{sandbox.restore();});varnow=newDate();it('setscreate_date',do

javascript - 如何在 ES6 中 stub 导出函数?

我有文件foo.js:exportfunctionbar(m){console.log(m);}还有另一个使用foo.js、cap.js的文件:import{bar}from'foo';exportdefaultm=>{//SomelogicthatIneedtotestbar(m);}我有test.js:importcapfrom'cap'describe('cap',()=>{it('shouldbar',()=>{cap('some');});});不知何故,我需要在测试中覆盖bar(m)的实现。有什么办法吗?附言我使用babel、webpack和mocha。

unit-testing - 如何在 Go 中构建 Mock 或 Stub 结构?

假设我有一个包含多个接口(interface)的Go包。对于这个例子,我将重点关注middleware.go中定义的一个名为Middleware的对象:typeMiddlewareinterface{//somefunctions}我有一些系统的其他部分使用它,所以为了更好地帮助测试系统的这些部分,我在mock_middleware.go中手动创建了一个模拟实现:typeMockMiddlewarestruct{}//implementations在没有测试的情况下构建二进制文件时,如何排除模拟类被构建到二进制文件中?我知道middleware_test.go将被排除在外,但我不想用该

unit-testing - 在 Golang 中 stub 函数

有一个函数在我负责单元测试的代码中不断出现(还没测试),定义如下://GetRetreivesanerrorwiththegivenaccesscode.funcGet(codeAccessCode)*ErrorSt{iferr,ok:=Errors[code];ok{err.Stack=utilityCore.GetCleanStack(logger.Instance.GetProjectNames())return&err}err:=NewError(string(ACPanic),fmt.Sprintf("Error'%s'can'tberetreived.",code),ESS

unit-testing - httptest.NewRequest 设置上下文 stub

我正在创建一个请求stub,以便将其传递给被测试的函数:request:=httptest.NewRequest("GET","http://example.com/foo",nil)问题:我还可以通过向其添加request-uuid值来为该请求stubContext对象吗? 最佳答案 你有请求,你可以在移交之前用它做任何你想做的事。使用Request.Context()要访问其上下文,请使用context.WithValue()派生一个新的context.Context在其中包含您的键值,并使用Request.WithContex