简体   繁体   English

用Mockito / Powermock模拟本地方法变量

[英]Mocking local method variables with mockito / powermock

I have a method which takes in a string as a parameter. 我有一个将字符串作为参数的方法。

However locally the method creates and uses a List and an instance of SingleColumnRowMapper. 但是,该方法在本地创建并使用List和SingleColumnRowMapper的实例。

Is there anyway using mockito/powermock once instances of these objects have been created/mocked in the unit test to place them as local variables into the method to be tested. 一旦在单元测试中创建/模拟了这些对象的实例,以将它们作为局部变量放入要测试的方法中,是否仍然可以使用嘲笑/ powermock。

Thank You 谢谢

SampleClass classInstance = Mockito.mock(SampleClass.class);

The above code mocks the instance creation of a class. 上面的代码模拟了类的实例创建。 If you want to create any instance, create it similarly and supply it to your method. 如果要创建任何实例,请类似地创建它,并将其提供给您的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM