We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
比如:连接一个redis,采用是静态代码块的方式。测试的时候是否能屏蔽了?不然每次测试该类都要加载连接
The text was updated successfully, but these errors were encountered:
支持直接Mock静态代码块内里的调用,具体一个实际的例子:
业务代码里使用静态代码块加载本地系统库,在运行单元测试的时候希望将它忽略。
public class JNIClass { static { System.loadLibrary("native-lib"); } // 以下具引入的方法省略 public native String xxxx(... ...); }
在测试时候时候Mock掉这个loadLibrary()调用,改为打印一行文本(这里是用独立的Mock类,也可以写在Test类里的Mock内部类里面):
loadLibrary()
public class JNIClassMock { @MockInvoke(targetClass = System.class, targetMethod = "loadLibrary") private void load(String libname) { System.err.println("loadLibrary " + libname); } }
Sorry, something went wrong.
No branches or pull requests
比如:连接一个redis,采用是静态代码块的方式。测试的时候是否能屏蔽了?不然每次测试该类都要加载连接
The text was updated successfully, but these errors were encountered: