在单位测试期间,如何制作Xunit模拟呼叫实际方法实现
我正在统计一种大方法,我无法对此进行任何更改。对于该工作,我使用Xunit,我们嘲笑了一些在此方法中使用的静态类。
我在这里所做的实际上是单位测试中的大型集成测试,我知道这不是最佳的,但这就是现在的情况。
静态课是这样嘲笑的。
private readonly Mock<IStaticClass> _mockStaticClass= new Mock<IStaticClass>() { CallBase = true};
在我对此方法的单元测试中,我们将其称为.dosomethingtodata(),我使用静态类中的方法。
),it.isany&lt; class2&gt;())。
_mockistaticClass.setup(x =&gt; x.manipulationAtaoneway(it.isany&lt; class&gt; (
我还需要模拟的静态类来使用另一种方法的实际实现来操纵我使用其他模型进行测试中的数据。所以我在单位测试中这样做。
_mockingistaticClass.setup(x =&gt; x.useactualImplemplementMethod(it.isany&lt; int&gt; it.isany&lt; int in int&gt; int&gt;)
。在单位测试调试期间,试图用notimplementedexception进行方法时,代码的实现.useactualimplemplementhodmedhod(int,int)。
我在做什么错?不应该为此调用实际实施吗?
谢谢大家的时间,复活节快乐。
I'm unittesting a big method, which I'm not able to make any changes to. For that job im using xUnit, and we have mocked some static classes which are used in this method unittest im doing.
What im doing here is actually a big integration test in a unit test, i know that is not optimal, but that is the situation as it stands right now.
The static class is mocked like this.
private readonly Mock<IStaticClass> _mockStaticClass= new Mock<IStaticClass>() { CallBase = true};
During my unit test of this method lets call it .doSomethingToData(), i use methods in the static class which i mock like this.
_mockIStaticClass.Setup(x => x.manipulateDataOneWay(It.IsAny<Class>(), It.IsAny<Class2>())).Returns(SomeObject);
Now here comes the problem.
I also need the mocked static class to use the actual implementation of another method to manipulate data which i have put into the test with my other mockings. So i do this in my unit test.
_mockingIStaticClass.Setup(x => x.useActualImplementationMethod(It.IsAny<int>, It.IsAny<int>)).CallBase();
But it does not work, ive put a breakpoint into the implementation of .useActualImplementationMedhod(int, int), but the code crashes when trying to make the methodcall with a NotImplementedException, during unit test debug.
What am i doing wrong? Shouldn't the actual implementation be invoked by this ?
Thankyou all for your time, and happy easter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论